//P898
#include <fstream>
using namespace std;
int main()
{
ofstream outFile("copy.txt");
if(!outFile)
{
cerr<<"cannot open for output\n";
return -1;
}
char ch;
while (cin.get(ch))
outFile.put(ch);
}
e:\源代码\c++ primer\chapter 20\20_6.cpp(10) : error C2065: 'cerr' : undeclared identifier
e:\源代码\c++ primer\chapter 20\20_6.cpp(10) : error C2297: '<<' : illegal, right operand has type 'char [24]'
e:\源代码\c++ primer\chapter 20\20_6.cpp(14) : error C2065: 'cin' : undeclared identifier
e:\源代码\c++ primer\chapter 20\20_6.cpp(14) : error C2228: left of '.get' must have class/struct/union type
e:\源代码\c++ primer\chapter 20\20_6.cpp(14) : fatal error C1903: unable to recover from previous error(s); stopping compilation
Error executing cl.exe.20_6.exe - 5 error(s), 0 warning(s)

解决方案 »

  1.   

    另相关贴见http://www.csdn.net/expert/topic/822/822062.xml?temp=.2603723,解决给80分!
      

  2.   

    加上如下语句:
    #include <iostream.h>
      

  3.   

    yeah,
    #include <iostream>   -> this is for STL.but not 
    #include <iostream.h>  -> this is for common c++ io stream 
      

  4.   

    果然如此!可是书上说fstream头文件已经包含了iostream头文件了,难道不对?
      

  5.   

    sorry, maybe you will never can build this sample in VC++.try to build it in gcc stl lib.in Vc version stl, it does has not implemented >> (string) for istream.