一个相当简单地的程序,为什么会出错?该怎么解决
一个相当简单地的程序,为什么会出错?
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
ofstream outfile( "out_file.txt ");
ifstream infile( "in_file.txt ");
if(!infile)
{ cerr < < "error:unable to open an input file " < <endl;
return -1;
}
if(!outfile)
{ cerr < < "error:unable to open an output file " < <endl;
return -2;
}
string str;
while(infile> > str)
{
outfile < <str < < ' ';
}
return 0;
}
提示错误:
test.cpp(22) : error C2137: empty character constant
我已经建立了一个out_put.txt和一个in_put.txt(内含一段文本)
------解决方案--------------------
' '
改成 ' '是一个空格吧,不是没有东西~
------解决方案--------------------
outfile < <str < < ' ';
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
ofstream outfile( "out_file.txt ");
ifstream infile( "in_file.txt ");
if(!infile)
{ cerr < < "error:unable to open an input file " < <endl;
return -1;
}
if(!outfile)
{ cerr < < "error:unable to open an output file " < <endl;
return -2;
}
string str;
while(infile> > str)
{
outfile < <str < < ' ';
}
return 0;
}
提示错误:
test.cpp(22) : error C2137: empty character constant
我已经建立了一个out_put.txt和一个in_put.txt(内含一段文本)
------解决方案--------------------
' '
改成 ' '是一个空格吧,不是没有东西~
------解决方案--------------------
outfile < <str < < ' ';