hi,
in this code:

#include "stdafx.h"
#include <iostream>

int main()
{
    using namespace std;
    cout << "Enter a value: ";
    double dX;
    cin >> dX;
 
    cout << "Enter a second value: ";
    double dY;
    cin >> dY;
 
    cout << "Enter one of the following: +, -, *, or /";
    char chChoice;
    cin >> chChoice;
 
    if (chChoice == '+')
        cout << dX << " + " << dY << " is " << dX + dY << endl;
    if (chChoice == '-')
        cout << dX << " - " << dY << " is " << dX - dY << endl;
    if (chChoice == '*')
        cout << dX << " * " << dY << " is " << dX * dY << endl;
    if (chChoice == '/')
        cout << dX << " / " << dY << " is " << dX / dY << endl;
 
    return 0;
}

this code works only, when i put #include "stdafx.h" before #include <iostream> what is the reason

regards
iammfa

Edited 6 Years Ago by Nick Evan: Added code-tags

Comments
>10 posts, still NO ***** CODE TAGS

Don't use <pre> and </pre>!, use the code tags: [ code=cplusplus ]...[ /code ], without spaces!

Thanks!

Edited 7 Years Ago by Nathan Campos: put in bold

I'm using c++ 2008 express, i removed stdafx.h, but the error return:

------ Build started: Project: Hello_World, Configuration: Debug Win32 ------
Compiling...
main.cpp
f:\tutorials\tut_c++\hello_world\main.cpp(1) : warning C4627: '#include <iostream>': skipped when looking for precompiled header use
        Add directive to 'stdafx.h' or rebuild precompiled header
f:\tutorials\tut_c++\hello_world\main.cpp(29) : fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?
Build log was saved at "file://f:\Tutorials\tut_c++\Hello_World\Debug\BuildLog.htm"
Hello_World - 1 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Having removed the stdafx.h abomination, you ALSO need to do

project->settings->compiler->pre-processor->precompiled headers and turn it OFF.

OK, the last couple of steps may vary, but you get the idea of where to start looking.

This article has been dead for over six months. Start a new discussion instead.