Help ?

If i read some of the other post i came ot the conclusion that this was somewhat gonna be the dummest question on the forum i guess... but here it goes anyway

When i use the Visual C++ compiler / environment ... the free downloadable one.
and i write this sourcecode


#include <iostream>

#include <iomanip>

using namespace std;

main()

{

cout >> "Hello world!";

cin.get();

}


it would run and compile great in Borland C++ 6 enterprise thingy (i'm talking bout both consoleapplications here)


The thing is, when i give that Program in Visual C++ i get this error

1>.\Oefeningetje.cpp(11) : fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source

Ok no sweat, i add the line #include "stdafx.h"  and since it also sais  " ....h" i'll chnage the < and > and paste in a .h

#include "iostream.h"

#include "iomanip.h"

#include "stdafx.h"

 

main()

{

cout >> "Hello world!";

cin.get();

}

compiling and i get these errors -.-'

1>Compiling...

1>Oefeningetje.cpp

1>.\Oefeningetje.cpp(7) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

1>.\Oefeningetje.cpp(8) : error C2065: 'cout' : undeclared identifier

1>.\Oefeningetje.cpp(9) : error C2065: 'cin' : undeclared identifier

1>.\Oefeningetje.cpp(9) : error C2228: left of '.get' must have class/struct/union

1> type is ''unknown-type''


since i'm a total program newby, i don't know what to do to run those programs decently....
Any help would be really appreciated



Answer this question

Help ?

  • Caged

    ok , thx

    i don't understand that much of that text since i don't know a lot from headers and have no clue what MFC is and neither do i know what "Afx" headers are.
    Because i don't know a lot from programming i'm a 17 year old kid that has bought some book to program in C++

    i know i need <iostream> for my "cin" and "cout" functions
    <iomanip> for setw(...) , setprecision, and so on
    <fstream> to redirect your output i thought and
    using namespace std;  so i don't have to type the full name std::cout and so on

    really i don't know anything from the history and my english isn't that well either, but safe yourself the problem to explain, thx anyways ^^

  • Mirek Smolinski

    I want to further point out that when the compiler searches for the #include "stdafx.h" it will ignore any line above it. 

    I explained a bit about precompiled headers under https://forums.microsoft.com/msdn/showpost.aspx postid=115695&siteid=1

    Brian

    PS To Microsoft: precompiled headers is a frequent usability issue for users migrating to Visual Studio or Visual Express C++ for the first time.  It might be a good area to focus on for the next version of VS!



  • AlvaroReis

    Your decleration of main is the problem. main is a function, functions MUST have return types and as the compiler error says, c++ doesn't support the default int type, so give main a return type.
    For the two errors following, ie cout and cin are undeclared. You took out the using namespace std; so obviously it wouldn't find them.
    The thing with stdafx.h is you chose to have precompiled headers in the project. So if you don't want to worry about that, then switch off precompiled headers in your project.

    #include <iostream>

    #include <iomanip>

    using namespace std;

    int main()

    {

    cout << "Hello world!"; //Please note the direction of the arrows

    cin.get();

    }

    I used the express edition of C++ and this compiled with no problems. I had to make sure that precompiled headers were off as I said earlier. If you need to know how to disable precompiled headers it is easy.

    Solution explorer window -> right click on the project name and select properties-> expand C++ and then select precompiled headers -> set the top option, Create/Use Precompiled Header to Not Using Precompiled Headers.



  • jjiffy

    "stdafx.h" came from a "standard" name for a user header that included "Afx" headers.  "AFX" (for "Advanced Framework") was what MFC was called before Microsoft acquired it.  Along the way, it made sense for Microsoft to precompile this header since MFC and Windows headers account for a lot of parsing time, so the name "stdafx.h" "stuck," even for projects that don't use MFC. 

    Brian


  • bodhi147

    wow, thx a bunch guys :)

    me with my silly low understanding of the language, i thought because there was
    STDafx  that it was some kind of include that would replace the
    using namespace std;
    no wonder it never worked

    and the >> arrows, that's cause i made it in like 5 secs ^^ didn't think about it

    Thx a lot for your help, now i got a new C++ environment, and it WORKS too :D





  • tom-taker

    I want to further point out that when the compiler searches for the #include "stdafx.h" it will ignore any line above it. 

    I explained a bit about precompiled headers under https://forums.microsoft.com/msdn/showpost.aspx postid=115695&siteid=1

    Brian

    PS To Microsoft: precompiled headers is a frequent usability issue when users migrating to Visual Studio or Visual Express C++ for the first time.  It might be a good area to focus on for the next version of VS!



  • Help ?