Declaring Strings in C++

Sharky Forums


Results 1 to 6 of 6

Thread: Declaring Strings in C++

  1. #1
    Tiger Shark Thraner's Avatar
    Join Date
    Sep 2001
    Location
    Parma, OH USA
    Posts
    809

    Declaring Strings in C++

    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!!
    Thraner

  2. #2
    Reef Shark
    Join Date
    Dec 2001
    Location
    Henrietta, New York, USA
    Posts
    264
    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.)

  3. #3
    Tiger Shark Thraner's Avatar
    Join Date
    Sep 2001
    Location
    Parma, OH USA
    Posts
    809
    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..
    Thraner

  4. #4
    Reef Shark
    Join Date
    Dec 2001
    Location
    Henrietta, New York, USA
    Posts
    264
    how is checkCharacter orginally declared?

  5. #5
    Tiger Shark Thraner's Avatar
    Join Date
    Sep 2001
    Location
    Parma, OH USA
    Posts
    809
    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!!
    Thraner

  6. #6
    Registered User peterlak's Avatar
    Join Date
    Dec 2002
    Location
    Bolton, Ontario, canada
    Posts
    8
    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.
    Last edited by peterlak; 12-19-2002 at 09:48 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •