void ReadFromFiletoString()
{
ifstream fin("data.txt",ios::in ); //创建输入文件流对象
string x;
while ( getline(fin,x) ) //从文件流中逐行读取字符串到x
{
cout << " Read from file: " << x << endl;
}
}
char cstr[6]="";
FILE *fp = fopen("C:\\1.txt","wr+");//打开一个文件
scanf(fp,"%5s",cstr);//从fp指向的文件流读5字节长的字符串赋给cstr
使用文件打开建立fostream() 用fopen赋予X,
使用fopen_s()比较简单