Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
data.txt ファイルがあります。
data.txt 1 2 3 4 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 9999 hello hello hello
ファイルを読み取り、最初の行を配列 [2] [2] に格納し、2 行目を配列 [3] [3] に格納し、ファイルに何が残っていても読み取りを停止するにはどうすればよいですか?
最も簡単な方法は、最初に getline を使用して行全体を読み取り、次に stringstream または sscanf() を使用することです。
すなわち
ifstream infile(ファイル名);
infile.getline(buffer,1024,'\n');
sscanf(buffer,"%d %d %d %d',&arr[0],&arr[1],&arr[2],&arr[3]);