strings

This is a discussion on strings within the C++ Programming forums, part of the General Programming Boards category; I thought i'd have a try at making myself a linked list, get some practise using pointers and such. Anyway, ...

  1. #1
    Let's do some coding! Welshy's Avatar
    Join Date
    Mar 2005
    Location
    Staffordshire University, UK
    Posts
    168

    strings

    I thought i'd have a try at making myself a linked list, get some practise using pointers and such. Anyway, in coding the CNode class i've had these errors:
    error C2146: syntax error : missing ';' before identifier 'name'
    error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
    with this code:
    Code:
    #ifndef CNODE_H
    #define CNODE_H
    
    class CNode
    {
    public:
    	CNode();
    	string name;
    	CNode *next;
    };
    
    #endif
    Error C4430 refers to the line 'string name;'. I've tried it with an Int and i dont get the errors, and i've tried including <string> but that doesnt help either. I know it's going to be something stupid, but i just cant see it, thanks for your help.

  2. #2
    Registered User mitakeet's Avatar
    Join Date
    Jun 2005
    Location
    Maryland, USA
    Posts
    212
    How about?

    Code:
    #ifndef CNODE_H
    #define CNODE_H
    
    #include <string> 
    
    class CNode
    {
    public:
    	CNode();
    	std::string name;
    	CNode *next;
    };
    
    #endif

    Free code: http://sol-biotech.com/code/.

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw

  3. #3
    Let's do some coding! Welshy's Avatar
    Join Date
    Mar 2005
    Location
    Staffordshire University, UK
    Posts
    168
    ohhh! I dont remember needing to use namespaces with strings....anyway, cheers mate

    EDIT: it actually works without the #include <string> too
    Last edited by Welshy; 07-13-2005 at 07:00 AM.

  4. #4
    Registered User mitakeet's Avatar
    Join Date
    Jun 2005
    Location
    Maryland, USA
    Posts
    212
    If it does it is because your compiler is guessing what you want. Trust me, relying on that is not portable!

    Free code: http://sol-biotech.com/code/.

    It is not that old programmers are any smarter or code better, it is just that they have made the same stupid mistake so many times that it is second nature to fix it.
    --Me, I just made it up

    The reasonable man adapts himself to the world; the unreasonable one persists in trying to adapt the world to himself. Therefore, all progress depends on the unreasonable man.
    --George Bernard Shaw

  5. #5
    Let's do some coding! Welshy's Avatar
    Join Date
    Mar 2005
    Location
    Staffordshire University, UK
    Posts
    168
    ah fair enough, it's included

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strings Program
    By limergal in forum C++ Programming
    Replies: 4
    Last Post: 12-02-2006, 02:24 PM
  2. Programming using strings
    By jlu0418 in forum C++ Programming
    Replies: 5
    Last Post: 11-26-2006, 07:07 PM
  3. Reading strings input by the user...
    By Cmuppet in forum C Programming
    Replies: 13
    Last Post: 07-21-2004, 06:37 AM
  4. damn strings
    By jmzl666 in forum C Programming
    Replies: 10
    Last Post: 06-24-2002, 02:09 AM
  5. menus and strings
    By garycastillo in forum C Programming
    Replies: 3
    Last Post: 04-29-2002, 11:23 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21