Results 1 to 9 of 9

Thread: C++ Question on String (Resolved)

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2003
    Posts
    153

    C++ Question on String (Resolved)

    But how come i cannot declare String??
    There's an error: Undeclared identifier "string"

    i have already included string.h

    #include <iostream>
    #include <fstream.h>
    #include <stdlib.h>
    #include <STRING>

    int main () {

    String A;
    return 0;
    }
    Last edited by Shaman; Dec 7th, 2003 at 09:34 PM.

  2. #2
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    This is a C# forum, not a C++ one.

    But it probably has something to do with the case.

    Try

    string instead of String

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2003
    Posts
    153
    it doesnt solve the problem
    Thanks

  4. #4
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985

    Re: C++ Question on String

    Originally posted by Shaman
    i have already included string.h
    No you haven't. including <string> does NOT guarentee that string.h is included. #include <string>, however, is the correct way.
    Originally posted by Shaman

    Code:
    #include <iostream>
    #include <fstream.h>
    #include <stdlib.h>
    #include <STRING>
    
    int main () {
    
    String A;
    return 0;
    }
    Are you coming from VB? DO NOT USE CAPITALS!!!, C++ is case sensative in everything. An INT is not the same as an int.

    To include and use a string:

    Code:
    #include <iostream>
    #include <string>
    
    int main () {
    string A;
    }
    Also, why do you have these in your code?:
    Code:
    #include <fstream.h>
    #include <stdlib.h>
    You declare the first header (iostream) correctly, these 2 deprecately and the last 1 incorrectly (capitals).

    If you want fstream and stdlib, do this:
    Code:
    #include <fstream>
    #include <cstdlib>
    Also, there is a C++ forum here, post C++ questions there. C# is an entirely different language with similar syntax in certain elements.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Nov 2003
    Posts
    153
    i have found the solution

    declaration is :

    #include <string.h>
    using namespace std;

    Its a stupid MS bug!
    Thanks

  6. #6
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    Its not a bug. My guess is you are using Managed C++, so you have to use the managed extensions.

  7. #7
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    Originally posted by Shaman
    i have found the solution

    declaration is :

    #include <string.h>
    using namespace std;

    Its a stupid MS bug!
    Thanks
    No, that is a bad solution because that is a deprecate header file. Include <string> not <string.h>.

    Because the header is deprecate, it doesn't even use the namespace std, so why did you even declare it?

    That isn't an MS bug, I'd suggest a nice C++ book that is caught up with the standard. www.nuwen.net click on C++, go to the bottom and check out the book recommendations. They are all great.

    Originally posted by DevGrp
    Its not a bug. My guess is you are using Managed C++, so you have to use the managed extensions.
    Managed extensions don't mean you use string.h instead of string. string.h is deprecate, he should be using <string>.

  8. #8
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    Originally posted by kasracer
    No, that is a bad solution because that is a deprecate header file. Include <string> not <string.h>.

    Because the header is deprecate, it doesn't even use the namespace std, so why did you even declare it?

    That isn't an MS bug, I'd suggest a nice C++ book that is caught up with the standard. www.nuwen.net click on C++, go to the bottom and check out the book recommendations. They are all great.

    Managed extensions don't mean you use string.h instead of string. string.h is deprecate, he should be using <string>.
    I was'nt refering to the <string> or <string.h>. I was refering to the using namespace std which is used when writing managed C++.

  9. #9
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    Originally posted by DevGrp
    I was'nt refering to the <string> or <string.h>. I was refering to the using namespace std which is used when writing managed C++.
    Uh, no. Managed C++ uses Microsoft's Propritary .NET framework.

    The using namespace directive just states that he will be using the namespace std, which is part of the standard C++ libraries.

    std has NOTHING to do with managed C++.

Posting Permissions

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



Click Here to Expand Forum to Full Width