Is it possible to store variables of more than one character? Because on the tutorial it says only one...I've been trying to figure it out but can't.
Thanks in advance
Is it possible to store variables of more than one character? Because on the tutorial it says only one...I've been trying to figure it out but can't.
Thanks in advance
Not sure what you mean, but perhaps you are looking to use arrays (and the standard containers)?
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Or std::strings?
Reading both char[] arrays and std::strings from the user is covered in this FAQ: http://faq.cprogramming.com/cgi-bin/...&id=1043284385
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
Sorry, I wasn't that clear. What I mean is, there are int, float and char which store variables. I wish to store more than one character so I can't use any of them. Is it possible to do that?
Yes, by using (statically or dynamically allocated) arrays, structs, std::string, std::vector, other standard containers, your own containers, etc.What I mean is, there are int, float and char which store variables. I wish to store more than one character so I can't use any of them. Is it possible to do that?
What problem are you trying to solve?
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Not really a problem I was just testing things. Thanks for the help. I'll try it now.
In most cases if you want to store multiple characters you are looking for a string. Use the C++ string class as a variable type just like int, double and char. A string literal is enclosed in double quotes (rather than single quotes like a character literal). So rather than:you can do:Code:char c = 'x';Make sure you #include <string> and otherwise it works pretty close to the same as the other types.Code:std::string s = "hello";
It sounds to me like he's asking if C++ has some sort of Variant type like they have in Visual Basic. Is that right? If that's the case, then there aren't any good ways to do it (why would you want to anyways?). The closest thing I can think of is a union.
Checked out VB's Variant, and it seems to be similiar to boost::any.It sounds to me like he's asking if C++ has some sort of Variant type like they have in Visual Basic. Is that right? If that's the case, then there aren't any good ways to do it (why would you want to anyways?).
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
More like boost::variant.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law