Why "Visual C++ 2008 Express Edition" is not Compiling a Simple C++ Program?

102 views Asked by At

Without wasting your time a short description is important to Describe the Problem. It is not compiling the Following Program with the error message that example.exe is not found when I tried to Build it.

#include <iostream>
using namespace std;
main()
{
    string name, surname;
    cout << "Enter your name: ";
    cin >> name;
    cout << "Enter your surname: ";
    cin >> surname;
    cout << "Welcome " << name << " " << surname;
 return 0;
}

enter image description here

1

There are 1 answers

4
Саша On BEST ANSWER

Your code is working on my end when I try to build it using GCC Compiler in Visual C++. Note: Other C++ Compilers need you to to declare the main function by using

int main() and you must have to create a header file main.h and include all libraries that you want to use. as I show you in my example of code. Try this code it should work on your end as well. Just you need to create an extra header file main.h and include iostream and string in it.

#include <iostream>
#include "main.h"
using namespace std;
main()
{
    string name, surname;
    cout << "Enter your name: ";
    cin >> name;
    cout << "Enter your surname: ";
    cin >> surname;
    cout << "Welcome " << name << " " << surname;
}