c++ 中vector怎么输出 结构体数据
#include <iostream>
#include <vector>
using namespace std;
typedef struct
{
string str;
int inode;
}StrId;
int main()
{
vector<StrId> t;
StrId str1;
str1.str = "This is a Test!";
str1.inode = 1;
t.push_back(str1);
for(vector<StrId>::iterator j=t.begin();j!=t.end();j++)
cout<< (*j).str<< " " << (*j).inode<<endl;
return 0;
}
D:\profile\CStud\CStud.cpp(1172) : error C2679: 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 conversio
这个程序cout<< (*j).str<< " " << (*j).inode<<endl;的这句话怎么写的 vector c++ struct
[解决办法]
cout<< (*j).str.c_str()<< " " << (*j).inode<<endl;
// 或者包含 #include <string>