各位好,我正在看C++Primer
书中提到一个string类型,是用来定义字符串的.其在头文件cstring中定义了。
但是我用VC++ 6.0,编译,但其中并没有cstring这个头文件啊!
vc中没有定义string这个类型,还是定义在其它头文件里面啊?
还有容器类型vector的头文件vector.h也没有。
这倒底是怎么回事啊?

解决方案 »

  1.   

    加两句,在使用之前
    using namespace std;
    include <string>
      

  2.   

    加了using namespace std;
    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";
      

  3.   

    加两句,在使用之前
    using namespace std;
    include <string>
      

  4.   

    加了,但还是不行啊!编译出现error C2871: 'std' : does not exist or is not a namespace
      

  5.   

    我一般这样用
    #include <vector>
    #include <string>int main()
    {
        std::vector<int> value_s ;
        
        value_s.push_back(.............
       std::string str ;   str = "abc" ;    
    }
      

  6.   

    我VC编译的结果是string这个头文件中没有定义string这个类啊
      

  7.   

    有谁能把我这个程序拿去编译一下,看看有多少错,这个是C++primer中的
      

  8.   

    这是这个程序编译后的结果Compiling...
    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)
      

  9.   

    #include<iostream>
    #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;
    }
      

  10.   

    知道是怎么回事了吗?你的 using namespace std;位置加错了,而且你还应该返回值(return 0;)
      

  11.   

    大哥们你们教错我了,应该是
    include<string>
    using namespace std
    你们都搞反了
      

  12.   

    to xuwj2000(海浪) :
    至少还有我没有错的嘛。
    你也够夸张的,你真的认为是别人教错了吗?他们既然都说到这个份上来了,就说明他们都已经知道怎么修改了。而你呢,居然连这么简单的问题也能弄错。using namespace std;必然是方在#include 文件之后的啊。
      

  13.   

    只加入iostream即可#include "stdafx.h"
    #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;
    }
      

  14.   

    好象VC的编译器和DEV C++的编译器相差很大。如果想学STL或是比较标准的C++,我觉得还是用DEV C++的好!!!