Click to See Complete Forum and Search --> : Declaring Strings in C++
Thraner
12-18-2002, 11:27 AM
Why when I declare a string in Visual C++ 6.0 like this:
string userDollars = "";
the word string doesn't show in blue like all other keywords? I think it should, and it's not, making me think it's not actually letting me declare a string. And yes I did #include <string>
Thanks!!
Frostburn
12-18-2002, 12:25 PM
Because string isn't a primitive data type its actually an array of characters char[]. To my knowledge Microsoft visual C++ doesn't highlight classes. Therefore, most classes will not be in blue(I've yet to see one that hasn't.)
Thraner
12-18-2002, 12:34 PM
Ok, that makes sense, but relative to that, look at this:
checkCharacter.assign(userInput, count, 1);
checkCharacter is defined as a char, userInput is defined as a string. I thought this statement should give checkCharacter the count'th letter in the userInput, but I get an error:
error C2228: left of '.assign' must have class/struct/union type
I don't get what is wrong here..
Frostburn
12-18-2002, 12:37 PM
how is checkCharacter orginally declared?
Thraner
12-18-2002, 12:42 PM
It was originally declared as a char. But after I wrote that last post, I changed all references to it to a string instead. I guess comparing a string of one character would be just as easy as comparing a char, and now my errors went away. Thanks for putting me on the right track!!
peterlak
12-19-2002, 08:48 PM
Originally posted by Frostburn
Because string isn't a primitive data type its actually an array of characters char[]. To my knowledge Microsoft visual C++ doesn't highlight classes. Therefore, most classes will not be in blue(I've yet to see one that hasn't.)
because string is a c++ class. ie.. char is a varibal.