Basic string help -- Did I step into the Twilight Zone?
-
Please help. I haven't programmed unmanaged C++ in 10 years. I'm trying to re-educate myself but I don't seem to be having a lot of luck. I swear I just stepped into the twilight zone. This code:
#include <string>
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
std::string s = " ";
printf(s);return 0;
}...fails to compile with 2 errors: C2039 "string is not a member of std" and C2065 "'s' undeclared identifier". So then I tried a "using namespace" declaration like this:
#include <string>
#include "stdafx.h"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
string s = " ";
printf(s);return 0;
}...and I still get the C2065, though the C2039 is gone. I also tried other ideas, like changing to . Nothing is working. What am I doing wrong??? I am using VS2010 on a Win7 (64bit) machine. Thanks for your help.
-
Please help. I haven't programmed unmanaged C++ in 10 years. I'm trying to re-educate myself but I don't seem to be having a lot of luck. I swear I just stepped into the twilight zone. This code:
#include <string>
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
std::string s = " ";
printf(s);return 0;
}...fails to compile with 2 errors: C2039 "string is not a member of std" and C2065 "'s' undeclared identifier". So then I tried a "using namespace" declaration like this:
#include <string>
#include "stdafx.h"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
string s = " ";
printf(s);return 0;
}...and I still get the C2065, though the C2039 is gone. I also tried other ideas, like changing to . Nothing is working. What am I doing wrong??? I am using VS2010 on a Win7 (64bit) machine. Thanks for your help.
-
Please help. I haven't programmed unmanaged C++ in 10 years. I'm trying to re-educate myself but I don't seem to be having a lot of luck. I swear I just stepped into the twilight zone. This code:
#include <string>
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
std::string s = " ";
printf(s);return 0;
}...fails to compile with 2 errors: C2039 "string is not a member of std" and C2065 "'s' undeclared identifier". So then I tried a "using namespace" declaration like this:
#include <string>
#include "stdafx.h"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
string s = " ";
printf(s);return 0;
}...and I still get the C2065, though the C2039 is gone. I also tried other ideas, like changing to . Nothing is working. What am I doing wrong??? I am using VS2010 on a Win7 (64bit) machine. Thanks for your help.
The precompiled header (
stdafx.h
) should always be the first header included. Also dump theprintf
. Try code like this:#include "stdafx.h" // Precompiled header should always be first.
#include <iostream> // We'll use cout instead of printf.
#include <string>
int _tmain(int argc, _TCHAR* argv[])
{
using namespace std;
string s = "Hello, world!";
cout << s << endl;
return 0;
}Steve
-
Please help. I haven't programmed unmanaged C++ in 10 years. I'm trying to re-educate myself but I don't seem to be having a lot of luck. I swear I just stepped into the twilight zone. This code:
#include <string>
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
std::string s = " ";
printf(s);return 0;
}...fails to compile with 2 errors: C2039 "string is not a member of std" and C2065 "'s' undeclared identifier". So then I tried a "using namespace" declaration like this:
#include <string>
#include "stdafx.h"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
string s = " ";
printf(s);return 0;
}...and I still get the C2065, though the C2039 is gone. I also tried other ideas, like changing to . Nothing is working. What am I doing wrong??? I am using VS2010 on a Win7 (64bit) machine. Thanks for your help.