substring error

This is a discussion on substring error within the C++ Programming forums, part of the General Programming Boards category; I get this error when I compile my code and all I am trying to do is get a substring. ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    26

    substring error

    I get this error when I compile my code and all I am trying to do is get a substring. Any suggestions.

    char szDrive[MAX_PATH]="c:\\";
    char dir[MAX_PATH]; BOOL bRet;
    bRet=GetCurrentDirectory(MAX_PATH,dir);
    printf("Current Working Directory is %s\n",dir);


    error C2228: left of '.substr' must have class/struct/union type

    The printf statement works just fine.

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    well you could start by posting the relevant code
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    It's because you are trying to use the .substr string memeber function on something other than a string.

    Perhaps you are trying to something like

    szDrive.substr(1,5) or something, but szDrive is a char*, not a std::string. I'd recommend just using the std::string class rather than char*, so you don't have to worry about overflowing your allocated memory, and all that other painful stuff associated with null terminated strings.

  4. #4
    Registered User
    Join Date
    Feb 2002
    Posts
    26
    PROBLEMS ALL RESOLVED...THANKS FOR SUGGESTIONS!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 02:07 AM
  3. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 03:09 AM
  4. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM

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