请问:在中使用字符串类string ,需要包含什么文件
已经试过 include<string>
              include<string.h>
              include<cstring>
              include<cstring.h> 
都没有通过。

解决方案 »

  1.   

    string类定义在STL中MSDN例:
    // string_getline_sample.cpp
    // compile with: /EHsc
    // Illustrates how to use the getline function to read a
    // line of text from the keyboard.
    //
    // Functions:
    //
    //    getline       Returns a string from the input stream.
    //////////////////////////////////////////////////////////////////////#pragma warning(disable:4786)
    #include <string>
    #include <iostream>using namespace std ;int main()
    {
       string s1;
       cout << "Enter a sentence (use <space> as the delimiter): ";
       getline(cin,s1, ' ');
       cout << "You entered: " << s1 << endl;;
    }
      

  2.   

    谢谢!但是,如果没有 using namespace std 那么编译的时候就会出现:文件string 找不到的错误提示。为什么会这样?
      

  3.   

    include<string> 和 include<string.h> 有什么区别?
      

  4.   

    #include <string.h>
    是指使用旧的C式库,它只是为了与旧的C编译器兼容才保留,将来会按新的C++标准去掉#include <string>
    指用新C++标准的模板类库(STL),是新的C++程序应当立刻采用的,除非为了兼容旧编译器而不采用
      

  5.   

    是不是只要用了using namespace std;
    那么c++primer里面的头文件都能被正确引用