Feb 27, 2012 at 1:27am UTC
Working on a project for school, need to use a couple string variables in the project but cannot get them recognized. I have #include <string.h> and also tried #include <string>, both valid header files(files exist and load) but string type remains undefined.
I am using Visual C++ 2010 Express.
Thanks for any hints.
Feb 27, 2012 at 1:28am UTC
It's #include <string> . C++ style headers don't have extensions, and C-converted headers are prefixed with C , such as #include <cmath> .
Wazzak
Last edited on Feb 27, 2012 at 1:29am UTC
Feb 27, 2012 at 1:49am UTC
#include <string> doesn't work either.
Here is a test program with string not working:
// string test.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <string>
int _tmain(int argc, _TCHAR* argv[])
{
string teststr;
return 0;
}
build log:
------ Build started: Project: string test, Configuration: Debug Win32 ------
stdafx.cpp
string test.cpp
\\vmware-host\shared folders\documents\visual studio 2010\projects\string test\string test\string test.cpp(10): error C2065: 'string' : undeclared identifier
\\vmware-host\shared folders\documents\visual studio 2010\projects\string test\string test\string test.cpp(10): error C2146: syntax error : missing ';' before identifier 'sth'
\\vmware-host\shared folders\documents\visual studio 2010\projects\string test\string test\string test.cpp(10): error C2065: 'sth' : undeclared identifier
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Feb 27, 2012 at 1:50am UTC
Qualify string with std:: . For example: std::string . Optionally, after the preporcessor directives, and before main( ) , write using namespace std; .
Wazzak
Feb 27, 2012 at 1:53am UTC
That did the trick, thank you.