Hi again I also need help with storing letters in varibles thanks again
Hi again I also need help with storing letters in varibles thanks again
char is the data type for storing single characters...Code:char x = 'c'; //variable x holds the letter 'c'
thanks agian Bench82 how u hold multipule charaters
characters stored contigiously (is that a word? - I mean "stored next to each other in memory" anyway) are generally known as strings... Since you're in the C++ forum, I'll assume you're not using C.. here is the C++ way to do it, using the C++ <string> library :Originally Posted by cgsarebeast
There's a different way to do it in C, which involves character arrays - that works in C++ too.. but in C++, use the method above unless you have a compelling reason to do otherwiseCode:#include <iostream> #include <string> using namespace std; int main() { string s = "Hello, World"; cout << s; cin.get(); }
o ic thanks but I'll give u an example:
(I know thats the example of the "enter your number" thing on this site but with words changed, I'm useing it 2 learn....)Code:#include <iostream> using namespace std; int main () { cout<<"Name 1.0 \n"; cout<<"Please Press Enter \n"; cin.get (); int x; cout<<"Please Input your name: "; cin>> x; cin.ignore (); cout<<"Is this your name?: "<< x <<"\n"; cin.get (); }
well ne ways I want that code 2 display a letter instead of a number and I dont know what varible 2 use or even if u use one
thanks.....
oh and yes I'm useing C++
Use the string variable that Bench82 showed you. He showed output, but it should be easy to change to input if you know how to input a number.
thanks, but with that how could the user change it like if I put a set value than if I put the value a sally than if there names not sally it would work?
Just replace int in your code with string (and add the #include <string>). They are both types that can be used in the same way in this case.
Then try it out and ask questions about the exact code if you get stuck.
YaY thanks Daved...