[問題] 從txt檔讀取數字 轉換成int變亂數
開發平台(Platform):dev c++
問題(Question):亂數
餵入的資料(Input):http://tinyurl.com/789al4v
預期的正確結果(Expected Output):可以把這些數字正確的儲存
錯誤結果(Wrong Output):http://tinyurl.com/6otsfum
程式碼:
#include <iostream>
#include <cstdlib>
#include <fstream>
using namespace std;
int main(void)
{
char txt[100];
int hw[100];
ifstream inf("C:/Users/USER/Desktop/DS/a.txt",ios::in);
if(inf.is_open())
{
while(!inf.eof())
{
inf.getline(txt,100,'\t');
cout <<txt <<'\t'<<endl;
}
}
else
{
cout<<"error";
}
for(int i=0;i<100;i++)
{
hw[i]=(int)txt[i];
cout <<hw[i]<<'\t';
}
system("pause");
return 0;
}
補充說明(Supplement):
因為是用getline來讀取資料
所以我認為要用strtok來切割資料
但是網路上的都看不太懂..囧
--
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 219.84.212.4
推
04/07 11:59, , 1F
04/07 11:59, 1F
→
04/07 12:04, , 2F
04/07 12:04, 2F
推
04/07 12:20, , 3F
04/07 12:20, 3F
推
04/07 12:51, , 4F
04/07 12:51, 4F
推
04/07 12:55, , 5F
04/07 12:55, 5F
→
04/08 08:17, , 6F
04/08 08:17, 6F
推
04/08 10:08, , 7F
04/08 10:08, 7F