Thread: Need help with String

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    5

    Need help with String

    for some reason my compiler doesn't see String data type.
    below is my code
    Code:
    #include<iostream.h>
    #include<string.h>
    
    void main()
    {
    
    
    	string name = " ";
    	string nameMin = " ";
    	string nameMax  = " ";
    
    ....
    ....
    ....
    }
    it tells me that string is undeclared identifier.

    Am I declaring it wrong?

    Thanks
    Last edited by deepblue; 10-23-2004 at 04:05 PM.

  2. #2
    C(++)(#)
    Join Date
    Jul 2004
    Posts
    309
    Try using:
    Code:
    char arrayname[max number of charsinarray];
    To code is divine

  3. #3
    Registered User
    Join Date
    Oct 2004
    Posts
    5
    Yes, i tried that.

    But isn't there an actual string data type, i.e. string name="John Doe";
    shouldn't it work? it doesn't even turn blue color like other data type.
    am i missing something?

  4. #4
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    See if the following works for you:
    Code:
    #include <iostream>
    using std::string;
    
    int main()
    {
    	string s;
    	return 0;
    }

  5. #5
    Registered User
    Join Date
    Oct 2004
    Posts
    5
    Gives me:

    error C2653: 'std' : is not a class or namespace name

    Maybe i have to reinstall compiler...

  6. #6
    Registered User
    Join Date
    Oct 2004
    Posts
    5
    My compiler verison is Microsoft Visual C++ v6.00, is it too old?

  7. #7
    Registered User
    Join Date
    Oct 2004
    Posts
    5

    It works now

    this is what I did

    Code:
    #include<iostream>
    #include<string>
    
    
    using namespace std;
    
    using std::string;
    
    
    int main()
    {
    
    
    	string name = " ";
    	string nameMin = " ";
    	string nameMax  = " ";

    and it worked

    Thanks everybody

  8. #8
    Occasionally correct Mr.OC's Avatar
    Join Date
    Oct 2004
    Posts
    6
    Quote Originally Posted by deepblue
    But isn't there an actual string data type, i.e. string name="John Doe";
    shouldn't it work? it doesn't even turn blue color like other data type.
    am i missing something?
    Just to clarify; std::string isn't a 'real' C++ data type. It's part of a Class. That's why it didn't turn blue, like char or int would.

    That's good that you got it working, though.

  9. #9
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    it was probably because you kept the ".h" at the end of the headers... you need the following for the string class:

    Code:
    #include <iostream>
    #include <string>
    
    using std::string;
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. compare structures
    By lazyme in forum C++ Programming
    Replies: 15
    Last Post: 05-28-2009, 02:40 AM
  2. OOP Question DB Access Wrapper Classes
    By digioz in forum C# Programming
    Replies: 2
    Last Post: 09-07-2008, 04:30 PM
  3. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 06:49 PM