0

How do you set variables equal to letters or words?

I've learned how to set and manipulate the value of variables but whenever I change the value to anything other than a number, there's an error.

13th Nov 2017, 3:04 AM
Leoliy Xolsun
Leoliy Xolsun - avatar
6 Réponses
+ 3
Yo so you are declaring an integer which can only be a whole number but you are trying to assign a string too it. You want to use an std::string. Lookup up how to use the string class and you can get this working.
13th Nov 2017, 12:51 PM
Arthur Tripp
Arthur Tripp - avatar
+ 2
If you can post an example of what you are trying to do it will help.
13th Nov 2017, 12:27 PM
Arthur Tripp
Arthur Tripp - avatar
+ 1
It’s because of the data type. It makes room in the memory for an int or char or whatever so you can’t just change it to a string it won’t fit.
13th Nov 2017, 3:18 AM
Arthur Tripp
Arthur Tripp - avatar
+ 1
int x; cin >> x; if x == "this" { cout << "that" << endl; } else { cout << "what?" << endl;
13th Nov 2017, 12:35 PM
Leoliy Xolsun
Leoliy Xolsun - avatar
+ 1
Ah! Thanks!
13th Nov 2017, 12:52 PM
Leoliy Xolsun
Leoliy Xolsun - avatar
0
@Arthur Tripp So is there a data type that WILL let me do this?
13th Nov 2017, 11:36 AM
Leoliy Xolsun
Leoliy Xolsun - avatar