共用方式為


Breaking Change: I/O stream changes

Original Code:

#include <iostream.h>

int main(int argc, char *argv[]) {
cout<<"Hello World\n";
}

Error VC2005 issues:

sample.cpp(1) : fatal error C1083: Cannot open include file: 'iostream.h': No such file or directory

Code after applying the fix:

#include <iostream>
using namespace std; //important to be able to use cout

int main(int argc, char *argv[]) {
cout<<"Hello World\n";
}

Thanks,
  Ayman Shoukry

Comments

  • Anonymous
    April 26, 2006
    May I have a question?
    What is the idea behind requiring the using directive for referencing header files?
    In other words ... Why can't we just use one of the two ways (define <> OR using namespace <>)?
    Thank you
  • Anonymous
    April 26, 2006
    Actually, the "using" just makes able to access anything that is defined within the namespace defined. Since "cout" is now part of the namespace "std" then accessing such namespace is required.

    You can even not use the "using" at all and just do something like:

    std::cout<<"Hello Worldn";

    Thanks,
     Ayman
  • Anonymous
    April 26, 2006
    Well, actually, what I meant is that the notion of cout belonging to namespace std has always been there. I just can't get the "change" (or am I missing something here?!). Sorry for the misleading (actually mistyped as well) comment before.
  • Anonymous
    April 27, 2006
    Based on what I understood from your question, here are more details (I hope I did understand you correct)

    In past versions of VC, eg. VC6.0, we had iostream.h (note the .h addition) which included other header files where cout was defined. Such header files did not define cout as part of the "namespace std". That is to say, we weren't conformant to the standard in such case.

    Actually, iostream.h was not close to the C/C++ conformance at all. Now it doesn't exist and we have iostream (without the .h) where lots of conformance issues were fixed including the cout and hence the use of the namespace std.

    By the way, to view the change, you can use the /P compiler switch which generates preprocessed version (a .i file) of the file you are compiling. Use that switch with VC2005 and also with VC6.0 (let us say on sample.cpp) and check out sample.i on both cases for the definition of "cout".

    Thanks,
     Ayman
  • Anonymous
    April 27, 2006
    Now I got the whole picture ... it's the shift from old header files to the new extensionless files with the motive of further conformance and adherence to the rules ...
    Thousand thanks.
  • Anonymous
    June 05, 2007
    Hi Ayman  I just encountered another problem when I replaced the iostream.h by iostream and using namespace std; It seems something's wrong in the official document 'cstdio' ? Here is the output error:C:Program FilesMicrosoft Visual Studio .NET 2003Vc7includecstdio(17) : error C2143: syntax error : missing '{' before ':'C:Program FilesMicrosoft Visual Studio .NET 2003Vc7includecstdio(17) : error C2059: syntax error : ':'C:Program FilesMicrosoft Visual Studio .NET 2003Vc7includecstdio(17) : error C2143: syntax error : missing '{' before ':'C:Program FilesMicrosoft Visual Studio .NET 2003Vc7includecstdio(17) : error C2059: syntax error : ':'C:Program FilesMicrosoft Visual Studio .NET 2003Vc7includecstdio(17) : error C2143: syntax error : missing '{' before ':'
  • Anonymous
    August 20, 2007
    <a href= http://pornositeworld.biz/map.html></a><br>
  • Anonymous
    October 10, 2007
    I have the same problem as above.Error 1 error C2143: syntax error : missing '{' before ':' c:program filesmicrosoft visual studio 8vcincludecstdio 25Error 2 error C2059: syntax error : ':' c:program filesmicrosoft visual studio 8vcincludecstdio 25Error 3 error C2143: syntax error : missing '{' before ':' c:program filesmicrosoft visual studio 8vcincludecstdio 25Error 4 error C2059: syntax error : ':' c:program filesmicrosoft visual studio 8vcincludecstdio 25
  • Anonymous
    January 19, 2008
    <a href= http://index1.megrep.com >statistics linking teen crime to single parent households</a>
  • Anonymous
    April 08, 2008
    <a href= http://index4.atsavo.com >askjeeveskids</a> <a href= http://index3.atsavo.com >tracey childers</a> <a href= http://index1.atsavo.com >media democracy</a> <a href= http://index2.atsavo.com >chase</a>
  • Anonymous
    April 06, 2009
    Hi,You must disable using precompiled header files.
  • Anonymous
    April 06, 2009
    Hi,You must disable using precompiled header files.