[問題] vector遇到小數點的問題!!!?

看板C_and_CPP作者 (#酷拔#)時間15年前 (2009/07/19 13:08), 編輯推噓1(104)
留言5則, 3人參與, 最新討論串1/4 (看更多)
請問版上大大~~ 我在使用vector的原始碼如下: ifstream fin(dataset.c_str()); //自行輸入的檔案名稱 ofstream fout("output.data"); string strLine; vector<vector<double> > Data2D; int count_column=0; while (getline(fin, strLine)) { count_column=count_column+1; stringstream ss(strLine); vector<double> row; int data; while (ss >> data) { row.push_back(data); } Data2D.push_back(row); } /*fout*/ for(k=0;k<count_column;k++) { for(j=0;j<(Dim);j++) { fout<<" "<<Data2D[k][j]<<" "; cout<<" "<<Data2D[k][j]<<" "; } fout<<endl; cout<<endl; } 程式執行到一半就出錯~就出現回報訊息。 如果把vector裡面型態改成folat..就可以執行,但沒辦法變成我要的結果。 我所輸入要輸入的檔案裡面的內容如下(其中三筆資料): 5 121 72 23 112 26.2 0.245 30 2 1 126 60 0 0 30.1 0.349 47 1 1 93 70 31 0 30.4 0.315 23 2 但程式執行後的結果變成這樣:(沒產生out.data,這是cout在cmd的擷取畫面) 5 121 72 23 112 26 3.67348e-040 7.35281e-040 1 1 126 60 0 0 30 3.67348e-040 7.35287e-040 1 1 93 70 31 0 30 3.67348e-040 7.34933e-040 5.60254e-039 碰到小數點後,vector的存入就產生問題。 請問有哪裡寫錯嗎?? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.120.48.7

07/19 13:39, , 1F
我猜是因為 int data
07/19 13:39, 1F

07/19 14:33, , 2F
最原本是vector<int>結果到小數點那個數字,後面就都沒值
07/19 14:33, 2F

07/19 14:34, , 3F
我才改成vector<double的>
07/19 14:34, 3F

07/19 16:52, , 4F
int data 拿到while外面,並改成double data
07/19 16:52, 4F

07/19 16:53, , 5F
不然就在while裡cout<<data,看它會印出來對不對
07/19 16:53, 5F
文章代碼(AID): #1AOgfLmj (C_and_CPP)
討論串 (同標題文章)
文章代碼(AID): #1AOgfLmj (C_and_CPP)