文件输入和输出的编译时出错的问题,请指点!
enhao 2004-04-19 11:16:16 源码如下:
#include <iostream.h>
#include <fstream.h>
#include <string.h>
int main()
{
ofstream outfile( "out_file" );
ifstream infile( "in_file" );
if( !infile )
{
cerr << "error:unable to open input file!\n";
return -1;
}
if( !outfile)
{
cerr << "error:unable to open output file!\n";
return -2;
}
string word;
while ( infile >> word )
outfile << word << ' ';
return 0;
}
在编译时报如下的错:
String.cpp
D:\VC315\222\String.cpp(61) : error C2065: 'string' : undeclared identifier
D:\VC315\222\String.cpp(61) : error C2146: syntax error : missing ';' before identifier 'word'
D:\VC315\222\String.cpp(61) : error C2065: 'word' : undeclared identifier
Error executing cl.exe.
是不是头文件没包含进来?