#include <iostream>
#include <fstream>
#include <string>
int main()
{
ofstream outfile( "c:\output.txt" );
ifstream infile( "c:\input.txt" );
if (!infile)
{cerr << "error:unable to open the input file\n";
return -1;}
if (!outfile)
{cerr << "error:unable to open the output file\n";
return -1;}
string word;
while(infile >> word)
outfile << word;
return 0;
}
编译出错,为什么,请大哥指导。。谢谢
using namespace std;加在main前面!
using namespace std;
:)
编译出错 你就仔细看看里面的错误信息。。
#include <iostream>
#include <fstream>
#include <string>
类似这样的都是引用C++标准库,所有C++标准库中的东西都封装在名为std的名字空间中,你要使用的话必需用using namespace std或者using std::xxx(你要用的名字)
名字空间没声明
恩,谢谢。可以编译了。但是运行的时候会出现error:unable to open the input file.
打不开输入文件,为什么?
c:\output.txt
应该是
c:\\output.txt
这叫转意。
哇,谢谢!