看板 HCHS_BioClub 關於我們 聯絡資訊
陣列型式(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
water2924:code也是我自己打來測試的 03/12 14:40