vector 输出问题
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <string.h>
#include <vector>
using namespace std;
int main(){
//读取myfile文件
char a[256];
ifstream infile;
infile.open("d:\\myfile.txt");
infile>>a;
infile.close();
//拆分字符串
const char *d=";,.";
char *p;
p=strtok(a,d);
vector<string> v;
while(p){
//printf("%s\n",p);
v.push_back(p);
p=strtok(NULL,d);
};
for(int j = 0; j < v.size(); ++j){
cout << v[j] << endl;
}
return 0;
}
它在倒数第4行 cout << v[j] << endl;报了个C2679的错,说是 二进制“<<”: 没有找到接受“std::basic_string<_Elem,_Traits,_Ax>”类型的右操作数的运算符(或没有可接受的转换)
怎么改呢
[解决办法]
for(int j = 0; j < v.size(); ++j){
cout << v[j] << endl;
}
//改为:
for(int j = 0; j < v.size(); ++j){
cout << v[j].data() << endl;
}