[問題] c++讀檔入指標陣列

看板C_and_CPP (C/C++)作者 (內褲魔)時間16年前 (2009/03/15 20:09), 編輯推噓1(103)
留言4則, 3人參與, 最新討論串1/1
想要讀入一個檔案如下 n tt and Ar ar . . . 想要把每行讀入一個指標陣列 又不想用gerline 目前的想法是 int main() { int i; char *number=new char[1000]; ifstream instream; instream.open("test.txt") for(i=0;i<5;i++) instream>>number; cout<<number[1]; instream.close(); } 本來以為輸出會是tt 結果是t 對指標陣列還不太熟 懇請版友解惑 感謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 134.208.33.70 ※ 編輯: cophie 來自: 134.208.33.70 (03/15 20:15)

03/15 20:17, , 1F
why not std::string ?
03/15 20:17, 1F

03/15 20:18, , 2F
你要的結果應是 cout << number;
03/15 20:18, 2F

03/15 20:56, , 3F
感謝樓上
03/15 20:56, 3F

12/28 23:26, , 4F
GJ
12/28 23:26, 4F
文章代碼(AID): #19lE_kw5 (C_and_CPP)
文章代碼(AID): #19lE_kw5 (C_and_CPP)