每次从文件 input.txt 中读取一行数据,将其以以下格式输出,如“michyang;25;(215021)65214795;13405054444”,输出格式为“姓名|年龄|电话|邮编|手机号”。
#include<iostream>
#include<fstream>
#include<string>
#pragma warning(disable:4996)
using namespace std;
const int MaxSize = 1000;
int main() {
	ifstream inf("inputFile.txt");
	char test[MaxSize] = {0, };
	string res[5];
	inf.getline(test, MaxSize);	//非成员函数可以传输到string中,成员函数getline只能到字符数组中
	//第一个参数是传输的字符数组,第二个是最多传输的size
	char *p;
	p = strtok(test, ";");		//第一个参数注意是字符数组
	for (int i = 0; p != NULL; i++) {
		res[i] = p;
		p = strtok(NULL, ";()");
	}
	
	cout << res[0] << "|" << res[1] << "|" << res[3] << "|" << res[2] << "|" << res[4] << endl;
}
原文:https://www.cnblogs.com/Za-Ya-Hoo/p/12680534.html