我有以下代码:
std::fstream out;
out.open(argv[1], std::fstream::in | std::fstream out);
if(out.is_open()){
在编译Code::Blocks
时,我收到以下错误:
在" out"
之前预期的主要表达
关于可能导致此错误的任何想法?
我试图重写文件5次
#include <fstream>
#include <iostream>
int main(int argc, char** argv) {
if (argc<2){
printf("Error! Usage: wrap.exe filename\n");
return -1;
}
std::fstream out;
out.open(argv[1], std::fstream::in | std::fstream out);
if(out.is_open()){
out.seekp(0,out.beg);
for(int i=0;i<5;i++)
{
while(!out.eof()){
out<<i;
}
}
}
else {
printf("Error! Problem with opening file to wrap!\n");
return -1;
}
out.close();
printf("File wrapped successfully!\n");
return 0;
}
答案 0 :(得分:4)
您在::
行的std::fstream
和out
之间写了一个空格,而不是open
。