0

I'm trying to build a DLL (but it works the same for static library) in Visual Studio 2017; this is my complete source.cpp file.

#include <iostream>
#include "stdafx.h"

void f() { std::cout << "I'm in f!\n"; }

When I compile, it complains that

error C2039: 'cout': is not a member of 'std'

If I take out stdafx.h, its complaint is

fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?

There's got to be a way to compile functions that use std::!

Topological Sort
  • 2,733
  • 2
  • 27
  • 54
  • 1
    `#include "stdafx.h"` must be the first include. The compiler ignores every line above that. This is a feature of MSVC precompiled headers. I am sure that there are many duplicates of this. – drescherjm Jul 01 '19 at 19:25
  • Sure couldn't find it! Happy to have the answer. – Topological Sort Jul 01 '19 at 19:59
  • Possible duplicate of [Cout is not a member of std, and other issues regarding c++](https://stackoverflow.com/questions/43904130/cout-is-not-a-member-of-std-and-other-issues-regarding-c) – drescherjm Jul 01 '19 at 20:26

0 Answers0