Jump to content

Visual C++ #include Problem


Recommended Posts

Hello, I've downloaded MS Visual C++ 2005 beta and want to start coding with it. Most of my experience is with command line unix based compilers (g++, etc), not gui compilers like this, so when I tried to test a real simple program:

#include <iostream>

int main ()
{
   cout << "Hello, World!";
   return 0;
}

I get this error message:

error C2065: 'cout' : undeclared identifier

I've checked everything I could think of, even the default path for all includes under setting tools->options, which was correct. Maybe I'm missing something simple.

Thanks

Link to comment
Share on other sites


Yes, this sounds familiar. Met with this trying out VS 2005 as well. Seems every function is now part of a "namespace" in the .net world. that means functions need to be referred to by their namespace (think of it as the library name) and the function name. It is specified with the scope resolution operator :: so that "cout" becomes "std::cout" or can be specified in the includes section as "using namespace std;"

This page clued me in ---> http://www.softadvances.com/stl/error_c206...identifier.html

Link to comment
Share on other sites

ahh thats right, namespace.. So I added that namespace line and now i get this error

Linking...
LIBCMTD.lib(wincrt0.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function _WinMainCRTStartup

so I searched on that error and found a solution here but it still did not resolve the problem. Only microsoft can make "hello world" a pain in the butt to compile, lol.

Thanks

Link to comment
Share on other sites

After looking at some other peoples code I found what I needed to do to fix the problem, this works now. Thanks

#include "stdafx.h"
#include <iostream>
using std::cout;

void main()
{
    cout << "Hello World";

}

Link to comment
Share on other sites

Yes, C++ in general is not for the faint of heart and MS standards (or lack of) can make it extra fun, but I suspect I would have similar problems trying to work with g++. Everything takes some getting used to.

Are you trying to compile this as a Win32 app or Win32 Console app? If the project is a Win32 app try changing it to Win32 console app. If you want a win32 app you have to include windows.h and change function "int main()" to something like "int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)"

Edit: OK, Just saw your last post. Glad it's working now. Wish I got more chances to work with C++, as I am very rusty. I use VFP mostly because everyone wants their app TODAY and C++ development just takes too long. Pity.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...