0

Hello DaniWebbers,

How would I go about taking user input into a string? It is not allowing me to do:

#include <iostream>
#include <string>
using namespace std;

int main() {

string users_name; // Reserved for the users name (input)
cout << "Enter your name: ";
cin >> users_name; // Compilation error 'No operator matches these operands'? 

getchar();
return 0;
}

I can't use "cin" nor "cin.getline()", not even "getline(cin,users_name)"...How do I get input form the user then put it into a string?

Thanks,
-camelCase

4
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by Stefano Mtangoo
0

what compiler are you using? Your program compiles without error on vc++ 2010 express.

replace getchar() with cin.get()

Edited by Ancient Dragon: n/a

0

just change the compiler to VS 2010 or QT 4.

QT is not compiler but GUI toolkit. may be you meant MinGW that comes with QT's IDE

0

yea i know that's sir thank's too much but i think it can develop the normal source code on it

any way VS 2010 is the best solution for it

0

what compiler are you using? Your program compiles without error on vc++ 2010 express.

replace getchar() with cin.get()

Following the AD and the GCC works fine!

#include <iostream>
#include <string>
using namespace std;

int main() {

string users_name; // Reserved for the users name (input)
cout << "Enter your name: ";
cin >> users_name; // Compilation error 'No operator matches these operands'? 
cout << "Your name is: "<<users_name<<endl;
cin.get();
return 0;
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.