无法打印向量字符串元素 [英] Not able to print the vector string elements
本文介绍了无法打印向量字符串元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是STL的新手,正在尝试学习向量.
我的代码段如下所示:
Hi,
I am new to STL and trying to learn about vectors.
My code snippet looks like the following:
#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;
int main() {
vector< string > svec( 10, string( "Hi" ));
for(vector<string>::iterator myIt= svec.begin();myIt != svec.end();myIt++) {
cout << *myIt;
}
cout << endl;
}
但是当我对此进行编译时,在以下语句中出现编译器错误:
But when I compile this I get the compiler error at statement:
cout << *myIt;
错误消息是:
The error message is :
Error 1 error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::basic_string<_Elem,_Traits,_Ax>' (or there is no acceptable conversion) 8
我该如何解决,
在此先感谢
How can I solve this,
Thanks in advance
推荐答案
尝试添加
#include <string>
这篇关于无法打印向量字符串元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文