#include "stdafx.h"
#include<iostream>
#include <fstream>
#include <string>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
ifstream in("w.txt");
string filename;
string line;
if(in)
{
//fread(buffer,sizeof(char),100,stream);
//m=strlen(buffer);
while (getline (in, line)) // line中不包括每行的换行符
{
cout << line << endl;
}
}
//}
//fclose(stream);
return 0;
#include<iostream>
#include <fstream>
#include <string>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
ifstream in("w.txt");
string filename;
string line;
if(in)
{
//fread(buffer,sizeof(char),100,stream);
//m=strlen(buffer);
while (getline (in, line)) // line中不包括每行的换行符
{
cout << line << endl;
}
}
//}
//fclose(stream);
return 0;
}
文件中存有信息是hello world,输出也是这个。主要运用了getline函数,如果用fread函数由于不是很很会,会出现乱码,没有geline简便。