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

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

replace getchar() with cin.get()

just change the compiler to VS 2010 or QT 4.

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

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

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;
}
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.