[問題] vector遇到小數點的問題!!!?
請問版上大大~~
我在使用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
07/19 13:39, 1F
→
07/19 14:33, , 2F
07/19 14:33, 2F
→
07/19 14:34, , 3F
07/19 14:34, 3F
推
07/19 16:52, , 4F
07/19 16:52, 4F
→
07/19 16:53, , 5F
07/19 16:53, 5F
討論串 (同標題文章)
以下文章回應了本文 (最舊先):
完整討論串 (本文為第 1 之 4 篇):