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

Salem commented: >10 posts, still NO ***** CODE TAGS -7

Recommended Answers

All 7 Replies

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

Thanks!

take out stdafx completely.

I'm learning to use the Microsoft Visual Studio and i hate this stdafx.h header!

GNU is better in my opinion!

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

stdafx.h in Visual Studio, have to be included on the project don't matter, but it have to be there!

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.

thanks Salem, all done well

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.