读书人

linux 下 string 类型 报错解决办法

发布时间: 2012-03-21 13:33:15 作者: rapoo

linux 下 string 类型 报错
linux 下c++程序中 使用了 string ttt;也包含了头文件 #include <string>,#include <string.h> ,但 g++ -c 时报错找不到string 类型,我试了一下 最简单的也报错!! 请大虾指点!!
#include<iostream>
#include<string>
int main()
{
string temp = "fdsafdas";
cout << temp << endl;
}



[解决办法]

加上 std 名称空间

C/C++ code
#include <iostream>      #include <string>int main() {          std::string temp("fdsafdas");    std::cout << temp << std::endl;      }
[解决办法]
C/C++ code
    #include <iostream>           #include <string>         using namespace std;      int       main()           {                           string       temp       =       "fdsafdas";                           cout       < <       temp       < <       endl;           } 

读书人网 >UNIXLINUX

热点推荐