The #include "pch.h"
(or #include "stdafx.h"
in old projects) must be placed before other statements.
Cannot resolve problem with cerr and endl
Windows 11, VS 2022, Version 17.13.3, C++, MFC
VS will not let me use those two operators. But the same code works in another project. Here is a screen capture of the code and the top of the Error List showing the complaint. Line 48 was added just for compile comparisons. Both lines are in the error list.
When the cursor is hovered over the offending line, and Copilot activated, here is the display
At the top of this file are these includes
#include "afxwin.h"
#include <iostream>
#include <string>
#include <ostream>
As I read the Copilot message, the use of std::cerr is legitimate. In a test project this code compiles and runs. The immediate goal is to copy that function from the test project to this one.
void CMFCdialog01Dlg::write_u64_to_hex(td_512_uint* input, int select) {``
``if (select < 0 || select >= U64_COUNT) {``
``std::cerr << "Invalid select index: " << select << std::endl;``
``return;``
``}
It uses that exact code.
A few hours studying this and searching did not reveal the problem. Just in case, these are the first errors in Error List, indicating this is not a cascading error problem.
What do I have wrong to cause this problem?
Community Center Not monitored
-
Viorel 122.5K Reputation points
2025-05-31T06:36:35.03+00:00