2013-07-02 5 views
0

이봐, 난 내가 벡터 scopids에있는 값을 할당 한 후 다시 STH구조의 벡터 값을 지정하거나 출력하는 방법은 무엇입니까?

multimap<unsigned, clusterinfo> classinfomap; 
clusterinfo clinfo; 
string id_req; 
//vector<unsigned> cluster_req_list and clustersipinfomap are some known from previous modules 
for (ib=cluster_req_list.begin(); ib !=cluster_req_list.end(); ib++) 
    { 
     if(clustersipinfomap.count(*ib)>0) 
    {   
     cout<<count1<<"\t"<<*ib<<"\t"; 
    clinfo.cluster= *ib; 
    std::pair<multimap<unsigned,sipinfo>::iterator, multimap<unsigned,sipinfo>::iterator> ret; 
    set<string>id_req_list; 
    id_req_list.clear(); 
    ret=clustersipinfomap.equal_range(*ib); 
    //obtain the id_req_list 
    for (multimap<unsigned, sipinfo>:: iterator ic=ret.first; ic!=ret.second; ++ic) 
    { 
     string id_tmp=ic->second.id; 
     id_req_list.insert(id_tmp); 
     *****(clinfo.scopids).push_back(id_tmp); //i got sth wrong here 


    } 

그들을 인쇄 밖으로 인쇄 잘못 몇 가지 문제가 같은 구조가

typedef struct CLUSTERINFO{ 
unsigned cluster; 
vector <string> scopids; 
}clusterinfo; 

것 같습니다있다 구조체의 벡터;

struct Foo 
{ 
    std::vector<std::string> vec; 
}; 

Foo f; 
std::string s("Hello, World!"; 
f.vec.push_back(s); 

인쇄하는 방법 : 당신은 아마 당신이 std::vector::push_back으로 달성 할 수있는 벡터에 요소를 추가 할 : 구조의 벡터에 값을 "지정"방법

multimap<unsigned, clusterinfo>::iterator ip; 
    for(ip= classinfomap.begin(); ip!=classinfomap.end(); ip ++) 
    { 
     cout<<ip->first <<"\t"<< ip->second.cluster<<endl; 
     for (unsigned it=0; it< (ip->second.scopids).size(); it++) 
     { 
      count<< (ip->second.scopids)[it] << endl; 
     } 

    } 
+1

03 "몇 가지 문제"와 "잘못" – Borgleader

+0

왜 당신은 모든 관련이없는 코드를 삭제하지 않고 단지 시도를 정의하십시오 간단한 벡터에'insert'를 호출합니까? – juanchopanza

+0

벡터에 push_back을 사용하고 – user1830108

답변

0

벡터의 내용?

C++ 11

for (const auto& e : f.vec) 
    std::cout << e << " "; 
std::cout << std::endl; 

C++

for (std::vector<std::string>::const_iterator it = f.vec.begin(); it != f.vec.end(); ++it) 
    std::cout << *it << " "; 
std::cout << std::endl;  
관련 문제