c++文件读取一行数据

#include
#include
using namespace std;
int main() {
	ifstream fin("retail.dat");
	string temp;
	char buf[1000];
	//用于截取子字符串的指针
	char* p;
	//缓冲区读入一行
	while (fin.getline(buf, 1000)) {
		//第一次将缓冲区中的字符串用空格分隔,并返回第一个子串
		p = strtok(buf, " ");
		while (p) {
			cout << p << " ";
			//NULL表示从上次停止的地方继续进行操作 返回下一个子串
			p = strtok(NULL, " ");
		}
		cout << endl;
	}
	return 0;
}

你可能感兴趣的:(C++)