locked
Count and Endl? codes dont work

    Question

  • Hello,

    Im trying to run this code, but im gettin an error:

    include <iostream>
    using
    namespace std;

    main()
    {
    cout<<
    "hi"<<endl;
    return 0;
    }

    the error:

    1>------ Build started: Project: test2, Configuration: Debug Win32 ------

    1> test2.cpp

    1>test2.cpp(4): warning C4627: '#include <iostream>': skipped when looking for precompiled header use

    1> Add directive to 'StdAfx.h' or rebuild precompiled header

    1>test2.cpp(12): fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "StdAfx.h"' to your source?

    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

    cant i use "count" and "endl"??
    many other codes dont work,

    Thanks.

    Wednesday, July 14, 2010 7:21 PM

Answers

  • 1>test2.cpp(4): warning C4627: '#include <iostream>': skipped when looking for precompiled header use

    1> Add directive to 'StdAfx.h' or rebuild precompiled header

    1>test2.cpp(12): fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "StdAfx.h"' to your source?

    A precompiled header is a file that includes a bunch of commonly used files and other configurations.  It is an optional thing you can do to reduce compilation times.  It looks like your project is expecting to use a precompiled header.  Here are a couple options:

    - Stop using precompiled headers: Project Properties -> C/C++ -> Precompiled Headers -> Not Using

    or

    - At the top of every .cpp file in the project, the first thing you should write is #include "stdafx.h", e.g.

     

    #include "stdafx.h"
    #include <iostream>
    using std::cout;
    using std::endl;
    
    int main()
    {
      cout << "Hi" << endl;
    }
    
    Wednesday, July 14, 2010 8:06 PM