[情報] C++ Vector

看板HCHS_BioClub作者 (Borussia M'gladbach)時間11年前 (2013/03/12 14:39), 編輯推噓0(001)
留言1則, 1人參與, 最新討論串1/1
陣列型式(Array idiom) vector http://caterpillar.onlyfun.net/Gossip/CppGossip/vector1.html http://developer.51cto.com/art/201002/183645.htm >------------------------------------------------------------ #include <stdio.h> #include <string> #include <iostream> #include <vector> using namespace std; typedef struct orbdata_ { string sName; int iNum; } orbdata; int main (int argc, char* argv[]) { vector <orbdata> vtmp; orbdata strTmp; string sInput; int iCount = 1; cout << "Please Enter your String(Enter '.' to stop):" << endl; do { //cin >> sInput; getline( cin, sInput ); if( sInput == "." ) { break; } strTmp.sName = sInput; strTmp.iNum = iCount++; vtmp.push_back(strTmp); } while(1); if( vtmp.size() > 0 ) { cout << "===========================================" << endl; } for( int i = 0; i < vtmp.size(); i++ ) { cout << vtmp[i].iNum << ":" << vtmp[i].sName << endl; } return 0; } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 111.243.173.206

03/12 14:40, , 1F
code也是我自己打來測試的
03/12 14:40, 1F
文章代碼(AID): #1HFiszQe (HCHS_BioClub)