首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

vector struct 调用 如何出有关问题了

2012-02-15 
vectorstruct 调用 怎么出问题了#includeiostream#includevector#includestdlib.h#includestring.h

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>

热点排行