坑爹的string(string操作中遇到的小问题)
今天练习c++的时候遇到坑爹的情况……
用到c++的string,首先是用cout输出string,
string c="abcdegrg"; cout<<c<<endl;
这个不应该有问题啊……?
但是编译是出现如下错误:
binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no acceptable conversion)
e:\编程\test1\af.cpp(43) : error C2144: syntax error : missing ';' before type 'int'
百度了一下原来没有加上#include<string>
另外如果想用下标方式访问string中的元素是必须加上#include<vector>否则会出现类似上面的问题。
<分享经验,分享快乐>2013-10-31