vector struct 调用 怎么出问题了
#include <iostream>
#include <vector>
#include <stdlib.h>
#include <string.h>
using namespace std;
struct tagTest
{
string aa;
string bb;
};
int main(int argc, char *argv[])
{
tagTest tTest[10];
tTest[1].aa = "test ";
tTest[1].bb = "test2 ";
tTest[2].aa = "test ";
tTest[2].bb = "test2 ";
tTest[3].aa = "test ";
tTest[3].bb = "test2 ";
tTest[4].aa = "test ";
tTest[4].bb = "test2 ";
vector <tagTest> vTest;
vTest.push_back(tTest[1]);
vTest.push_back(tTest[2]);
vTest.push_back(tTest[3]);
vTest.push_back(tTest[4]);
//如何把tTest存入vTest里?
vector <tagTest> ::const_iterator p1;
//system( "PAUSE ");
for(p1=vTest.begin();p1!=vTest.end();p1++)
cout < < (*p1).aa < <endl;
return 0;
}
[解决办法]
头文件,应该包含 <string> ,而不是 <string.h>