作者cophie (內褲魔)
看板C_and_CPP
標題[問題] c++讀檔入指標陣列
時間Sun Mar 15 20:09:17 2009
想要讀入一個檔案如下
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)
1F:→ legnaleurc:why not std::string ? 03/15 20:17
2F:→ legnaleurc:你要的結果應是 cout << number; 03/15 20:18
3F:→ cophie:感謝樓上 03/15 20:56
4F:推 jasonfghx:GJ 12/28 23:26