HI, i've posted only once before, but i have a question. I would like to know if there is a way in C++ to enter a string of text as a variable as in var="your name", that's it
HI, i've posted only once before, but i have a question. I would like to know if there is a way in C++ to enter a string of text as a variable as in var="your name", that's it
like:
or:Code:string var = "your name";
?Code:char var[] = "your name";
and
char *str = "my string";
-LC
Asking the right question is sometimes more important than knowing the answer.
Please read the FAQ
C Reference Card (A MUST!)
Pointers and Memory
The Essentials
CString lib
Well, don't use the last syntax you were given, it is better to use an array than a pointer to declare a string.
ok, what i want to do is to have the user imput thier name, and it outputs it in all the right places, so that i could make my program more personalized. I want the value to be like a float or int,where the user could imput (cin) thier name, and i twould output the value later on.
thx. for your time,
Pyrotherm
Then, if you are using C++, use string.
Or, much more correctly:Originally posted by Lynux-Penguin
and
char *str = "my string";
-LC
const char *str = "my string";
It's bad karma to take advantage of the single instance of an implicit conversion from const to non-const.
You ever try a pink golf ball, Wally? Why, the wind shear on a pink ball alone can take the head clean off a 90 pound midget at 300 yards.
when you accept the value from the user use any of the following
this will allow for any white space between the first and last nameCode:cin.get(aString, 50 ) // accept a string up to 50 or '\n' cin.get(astring,50,'$') // accept to 40 or '$' is found