1. FILE
文件读:FILE* fs = fopen("file.txt","r");
while( 1 )
{
char lineHeader[128];
// read the first word of the line
int res = fscanf(file, "%s", lineHeader); //逐行扫描,遇到空格或者换行停止
if (res == EOF)
break;
if ( strcmp( lineHeader, "v" ) == 0 )
{
}
}
文件写:FILE* fs = fopen( " file.txt", "w");
错误: error c2664:"fopen" 不能将参数2从"char" 转换为 " const char *" 原因:参数 "r" 写成了 'r'
2. FSTREAM
文件读:
fstream fin;
fin.open("file.txt", ios::in);
fin >> &x;
文件写
fstream fout;
fout.open("testdata/result1.obj",ios::out);
fout << "v " << point[0] << " " << point[1] << " " << point[2] << endl;
其中 参数 ios::app 是在文件结尾直接写,不清除文件内容