Re: [問題] 將存在vector的字串印出來

看板C_and_CPP作者 (我要盡全力幫忙KOBE老大)時間12年前 (2011/11/04 17:00), 編輯推噓0(002)
留言2則, 1人參與, 最新討論串2/2 (看更多)
剛剛解決的了這個問題,原來把輸出的部份放到while loop裡面就能解決, 雖然我不知道原因 #include <cstdlib> #include <iostream> #include <vector.h> #include <string.h> using std::vector; using std::string; using std::cout; using std::endl; /* * */ int main(int argc, char** argv) { vector<string> vstring; string sstring; while(cin>>sstring){ vstring.push_back(sstring); for(vector<string>::size_type vsize=0;vsize!=vstring.size();++vsize) cout<<vstring[vsize]<<endl; } return 0; } ※ 引述《LamarOdom7 (我要盡全力幫忙KOBE老大)》之銘言: : 開發平台(Platform): (Ex: VC++, GCC, Linux, ...) : netbean : 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) : no : 問題(Question): : 輸入一串文字到vector中,然後再把他印出來 : 餵入的資料(Input): : 使用者自行輸入 : 預期的正確結果(Expected Output): : 印出當初輸入的字串 : 錯誤結果(Wrong Output): : 程式碼(Code):(請善用置底文網頁, 記得排版) : http://codepad.org/ei8x7S4F : 補充說明(Supplement): : 我是新手,剛碰vector,也還在嘗試各種想法,所以出了這個題目給自己練習,卻卡關 : 不知道有人可以提示一下怎麼解決嗎? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 60.251.167.2

11/04 17:10, , 1F
你原本那個code就沒有什麼問題了,只是缺少結束機制
11/04 17:10, 1F
我剛剛發現原因了! 哈~ 我真蠢..... ※ 編輯: LamarOdom7 來自: 60.251.167.2 (11/04 17:11)

11/04 17:11, , 2F
11/04 17:11, 2F
文章代碼(AID): #1EiwcyPv (C_and_CPP)
文章代碼(AID): #1EiwcyPv (C_and_CPP)