[問題] 從txt檔讀取數字 轉換成int變亂數

看板C_and_CPP作者 (原來不只一個人)時間12年前 (2012/04/07 11:39), 編輯推噓5(502)
留言7則, 7人參與, 最新討論串1/1
開發平台(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
你強制轉型就是直接把 txt[i]的 ansi值複製過去阿
04/07 11:59, 1F

04/07 12:04, , 2F
不解..囧
04/07 12:04, 2F

04/07 12:20, , 3F
atoi
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
sscanf
04/08 08:17, 6F

04/08 10:08, , 7F
文章代碼(AID): #1FVxS5on (C_and_CPP)