Cannot resolve problem with cerr and endl

Bryan Kelly 486 Reputation points
2025-05-31T04:44:11.4666667+00:00

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.

cerr1

When the cursor is hovered over the offending line, and Copilot activated, here is the display

cerr2

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
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 122.5K Reputation points
    2025-05-31T06:36:35.03+00:00

    The #include "pch.h" (or #include "stdafx.h" in old projects) must be placed before other statements.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.