文件-读文件

#include "stdafx.h"
#include <fstream>
#include <string>
#include <iostream>
int _tmain(int argc, _TCHAR* argv[])
{
	std::string filename = "outfile.txt" ;
	std::ifstream infile(filename.c_str());
	int num_tries = 0;
	int num_cor = 0;

	if(!infile)
	{
		std::cout<<"Open file '"<<filename<<"' failed"<<std::endl;
	}
	else
	{
		std::string name;
		int age;
		int height;
		
		while(infile>>name)
		{
			infile>>age>>height;
			std::cout<<name<<" "<<age<<" "<<height<<std::endl;

		}
	}
	return 0;
}




文件outfile.txt内容

John 25 172
Lucia 22 165
Jack 29 179
Mark 35 174

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