Hello members,

I have started studying C++ with the book "C++ primer"( by Stanley B. Lippman, Josée Lajoie& Barbara E. Moo). I use Visual Studio 2012 Ultimate and make my projects on Win32ConsoloApllication. There was an example and I wanted to make it over for myself.

#include <iostream>

int main()
{
    std::cout << "Enter two numbers:" << std::endl;
int v1 = 0, v2 = 0;
std::cin >> v1 >> v2;
std::cout << "The sum of " << v1 << " and " << v2
<< " is " << v1 + v2 << std::endl;
return 0;
}

What do I have to do? How do I know what kind of error I have? I can I deal next time against a error?
I hope you can help me as soon as possible, because I can't go further with this error.

Greetings

Kareem Klas

Recommended Answers

All 3 Replies

I'm using VS2010, so it may be different. But your subsystem is probably set to Windows. So open the project properties (right click on the project in Solution Explorer and click Properties). Then under Configuration Properties -> Linker -> System make sure it's set to Console.

Basically, when Console is defined, it uses the main() function as a starting point. However, when Windows is defined, it expects a WinMain() function (with no attached console; used for GUI applications).

CGSMCMLXXV does make a fair point about keeping the console window open after the result is displayed.

Both thanks for your reply.
But to CGSMCMLXXV , you're right there's error otherwise there would be a red place indicated where the error is while debugging. But the post you send me is not really of a help, maybe me for the future but not for this. I don't have problem that when I build it directly closes, I have problem that it says that it failed to build.

To nmaillet, I have picture of the properties because I can't find the section about the linker.

Also I have to mention when I make a code like :

//Just really simple

#include <iostream>

int main()
{
 return0;
}

It builds but closes directly, for this the post from CGSMCMLXXV is very useful, but the other one not.

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.