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 (12)
  1. Bahaa says:

    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

  2. AymanS says:

    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

  3. Bahaa says:

    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.

  4. AymanS says:

    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

  5. Bahaa says:

    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.

  6. baidu says:

    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 ‘:’

  7. Steve says:

    I have the same problem as above.

    Error 1 error C2143: syntax error : missing ‘{‘ before ‘:’ c:program filesmicrosoft visual studio 8vcincludecstdio 25

    Error 2 error C2059: syntax error : ‘:’ c:program filesmicrosoft visual studio 8vcincludecstdio 25

    Error 3 error C2143: syntax error : missing ‘{‘ before ‘:’ c:program filesmicrosoft visual studio 8vcincludecstdio 25

    Error 4 error C2059: syntax error : ‘:’ c:program filesmicrosoft visual studio 8vcincludecstdio 25

  8. klira says:

    <a href= http://index1.megrep.com >statistics linking teen crime to single parent households</a>

  9. Olgunka-yd says:

    <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>

  10. REZA says:

    Hi,

    You must disable using precompiled header files.

  11. REZA says:

    Hi,

    You must disable using precompiled header files.

Comments are closed.

Skip to main content