各位好,我正在看C++Primer
书中提到一个string类型,是用来定义字符串的.其在头文件cstring中定义了。
但是我用VC++ 6.0,编译,但其中并没有cstring这个头文件啊!
vc中没有定义string这个类型,还是定义在其它头文件里面啊?
还有容器类型vector的头文件vector.h也没有。
这倒底是怎么回事啊?
书中提到一个string类型,是用来定义字符串的.其在头文件cstring中定义了。
但是我用VC++ 6.0,编译,但其中并没有cstring这个头文件啊!
vc中没有定义string这个类型,还是定义在其它头文件里面啊?
还有容器类型vector的头文件vector.h也没有。
这倒底是怎么回事啊?
using namespace std;
include <string>
include <string>
也不行啊!
书中的源程序如下:
#include<iostream>
#include<string>
int main()
{
int errors=0;
string str("a very long literal string");
for(int ix=0;ix<100000;++ix)
{
int len=str.size();
string str2=str;
if(str!=str2)
++errors;
}
cout<<"String class:"
<<errors<<" errors occurred.\n";
}
using namespace std;
include <string>
#include <vector>
#include <string>int main()
{
std::vector<int> value_s ;
value_s.push_back(.............
std::string str ; str = "abc" ;
}
primer3_14.cpp
D:\CHENG\primer\primer3_14\primer3_14.cpp(1) : error C2871: 'std' : does not exist or is not a namespace
D:\CHENG\primer\primer3_14\primer3_14.cpp(7) : error C2065: 'string' : undeclared identifier
D:\CHENG\primer\primer3_14\primer3_14.cpp(7) : error C2146: syntax error : missing ';' before identifier 'str'
D:\CHENG\primer\primer3_14\primer3_14.cpp(7) : error C2065: 'str' : undeclared identifier
D:\CHENG\primer\primer3_14\primer3_14.cpp(10) : error C2228: left of '.size' must have class/struct/union type
D:\CHENG\primer\primer3_14\primer3_14.cpp(11) : error C2146: syntax error : missing ';' before identifier 'str2'
D:\CHENG\primer\primer3_14\primer3_14.cpp(11) : error C2065: 'str2' : undeclared identifier
D:\CHENG\primer\primer3_14\primer3_14.cpp(15) : error C2065: 'cout' : undeclared identifier
D:\CHENG\primer\primer3_14\primer3_14.cpp(16) : error C2297: '<<' : illegal, right operand has type 'char [14]'
D:\CHENG\primer\primer3_14\primer3_14.cpp(17) : warning C4508: 'main' : function should return a value; 'void' return type assumed
Error executing cl.exe.primer3_14.obj - 9 error(s), 1 warning(s)
#include<string>
using namespace std;
int main()
{
int errors=0;
string str("a very long literal string");
for(int ix=0;ix<100000;++ix)
{
int len=str.size();
string str2=str;
if(str!=str2)
++errors;
}
cout<<"String class:"
<<errors<<" errors occurred.\n";
return 0;
}
include<string>
using namespace std
你们都搞反了
至少还有我没有错的嘛。
你也够夸张的,你真的认为是别人教错了吗?他们既然都说到这个份上来了,就说明他们都已经知道怎么修改了。而你呢,居然连这么简单的问题也能弄错。using namespace std;必然是方在#include 文件之后的啊。
#include <iostream>using namespace std;int main(int argc, char* argv[])
{
string strText("this is a demo for test the string"); cout << strText.c_str() << endl;
return 0;
}