c++读取txt中用空格格开的数字?

rt ,用getline如何实现?每一行都易坐标,x和y用空格隔开的。
是从txt文档读取

第1个回答  2014-04-21
int x,int y;
while(cin)
{
cin.getline(x,10,‘ ’);//最好还是用cin>>x>>y实现更理想
cin.getline(y,10,‘ ’);
cin.get();//读取换行
}
第2个回答  2014-04-21
输入文件流:ifstream相当于cin,会自动按照空格隔开,将流赋值到变量里就行
第3个回答  2014-04-21
不用getline
f>>x>>y;
第4个回答  2014-04-21

int x = 0, y = 0;

cin>>x>>y;

#include <fstream>
int x = 0, y = 0;
fstream txtIn("abc.txt", ios::in | ios::out);
txtIn >> x >> y;

本回答被提问者采纳
相似回答