-3

I have always used Linux Text Editor for C/C++ coding. I'm totally new to Visual Studio. I downloaded Visual Studio 2013 and wrote a very basic code. Before I tell you my problem, I think I should mention how I opened the new project so that it's not the matter of opening a wrong new project!

So here it is:

File > New > Project > Visual C++ > Win32 Console Application > ok > (Window appears saying "Welcome to Win32 Application wizard") > Next > checked the box saying "Empty Project" under Additional options > Finish

So then, I just right click on the "Source Files" > Add > New Item > C++ File(.cpp) > Add

Then my desired window appears so that I can write some code that should work!!

I wrote the following (very basic code) in Visual Studio 2013:

#include <iostream>

using namespace std;

int main()
{

    cout << "What's your name?";   
    string name;  
    cin >> name;  
    cout << "Enter your age: ";  
    int age;  
    cin >> age;  
    cout << "In a decade, you will be " << age + 10 << "years old!" << endl;
    return 0;

}

To run it, when I press "Local Windows Debugger", a box appears saying: "There were build errors. Would you like to continue and run the last successful build?"

I pressed "Yes"

Then it shows another box saying "Unable to start the program....the system cannot find the file specified"

The following errors I get to see in the error list:

no operator ">>" matches the operands 
operand types are: std::istream >> std::string

I would appreciate your help. Thanks.

Rico
  • 58,485
  • 12
  • 111
  • 141
user3303858
  • 7
  • 1
  • 1
  • Thanks a lot Igor. Cn u please also tell me after fixing this error, the output window not staying after the result has come. I mean it just appears for a like a second after the final result and then disppears. Is there any way of keeping it for long? – user3303858 Feb 12 '14 at 23:40
  • @user3303858 http://stackoverflow.com/questions/1775865/preventing-console-window-from-closing-on-visual-studio-c-c-console-applicatio – drescherjm Feb 12 '14 at 23:44

3 Answers3

0

You forgot to include C++'s string library. Adding

#include <string>

at the beginning of your file should make it work.

0

You can either do:

std::string name;

or include string class at the top:

#include <string>
James
  • 176
  • 1
  • 4
  • 16
0
  1. You did not include string class like #include<string>
  2. Use cin.getline(name) to take input in string otherwise it will take just a word as input, because ">>" operator ignore white spaces (space, tab etc..)
  3. When you find this Box Message: "There were build errors. Would you like to continue and run the last successful build?" Do not press YES because it uses the last error free build to execute your program.
Abdullah Aziz
  • 700
  • 5
  • 11