Working with Strings and Numbers

This is a discussion on Working with Strings and Numbers within the C++ Programming forums, part of the General Programming Boards category; I'm converting a exe to a dll. I need to capture the errors and display them at the end of ...

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    80

    Working with Strings and Numbers

    I'm converting a exe to a dll. I need to capture the errors
    and display them at the end of the program instead of displaying the error as it happens (the way it works now).

    I set up a variable named warning list:

    Code:
    WarningList[255];
    I replaced the spots where the program would display errors
    with the following code (Note - the old code would display variables of different types:

    Old Code/
    Code:
     cout<<"A";
    scrn<<"NOTE: The bond between atoms "<<papa[q[j]]<<" and "<<q[j]<<" is not in an aromatic ring.\n";
     scrn<<"It will be interpreted as a single bond.\n";
    New Code/
    Code:
     if (strlen(WarningList) > 1) {
    strcat(WarningList,",");	
    }
    
    strcat(WarningList,"The bond between atoms ");
    strcat(WarningList,papa[q[j]]);
    strcat(WarningList,"and ");
    strcat(WarningList,q[j]);
    strcat(WarningList," is not in an aromatic ring. It will be interpreted as a single bond.");
    The problem I'm running into is including variables that are integers in my WarningList. Here's the specific error:

    C:\MSDEV\Projects\cfx_SmilesParser\request.cpp(452 ) : error C2664: 'strcat' : cannot convert parameter 2 from 'int' to 'const char *' (new behavior; please see help)

    I'm new to C++ and have been having a hard time figuring out how to get this to work. Any advice would be greatly appreciated.

  2. #2
    Unregistered User
    Join Date
    Sep 2005
    Location
    Antarctica
    Posts
    341
    if you were using std::string, I would say to use std::stringstream, but since you're not, do this instead of strcat:

    Code:
    sprintf(WarningList, "%s%d", WarningList, q[j]);
    assuming that the q[j] is where your int is.

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    80
    Thanks, that worked great.

  4. #4
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,674
    Quote Originally Posted by rockytriton
    if you were using std::string, I would say to use std::stringstream, but since you're not, do this instead of strcat:

    Code:
    sprintf(WarningList, "%s%d", WarningList, q[j]);
    assuming that the q[j] is where your int is.
    I'm not sure but I think the behavior is undefined if you copy between strings that overlap. Maybe someone else knows for certain...
    I used to be an adventurer like you... then I took an arrow to the knee.

  5. #5
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    use stringstreams instead. Then you can use your old code with very little modifications.

  6. #6
    Registered User
    Join Date
    Aug 2005
    Posts
    80
    I'm using Visual C++ version 4. sstreams.h is not in the include folder. I've looked on the Web for it, but there are a bunch of different versions of it. How can I get the correct
    sstream.h file?
    Last edited by jamez05; 10-19-2005 at 11:27 AM. Reason: spelling

  7. #7
    Registered User
    Join Date
    Jan 2005
    Posts
    7,319
    It's sstream without the .h, but if you are using VC++ 4 then it might not work anyway. Check dinkumware.com to see if they have a standard library for that version.

  8. #8
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,674
    Quote Originally Posted by Daved
    It's sstream without the .h, but if you are using VC++ 4 then it might not work anyway. Check dinkumware.com to see if they have a standard library for that version.
    If not sstream then he might have strstrea.h but I shudder at the thought of having to use that.
    I used to be an adventurer like you... then I took an arrow to the knee.

  9. #9
    Unregistered User
    Join Date
    Sep 2005
    Location
    Antarctica
    Posts
    341
    Quote Originally Posted by hk_mp5kpdw
    I'm not sure but I think the behavior is undefined if you copy between strings that overlap. Maybe someone else knows for certain...
    Hmm, I haven't heard of that, if you are right there is probably a lot of undefined behavior in a lot of applications that I've worked on!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 12-21-2007, 12:38 PM
  2. strings and numbers
    By jrahhali in forum C++ Programming
    Replies: 5
    Last Post: 09-23-2003, 12:24 PM
  3. strings and numbers
    By Granger9 in forum C Programming
    Replies: 3
    Last Post: 09-10-2002, 04:11 PM
  4. convert numbers to strings
    By Unregistered in forum C++ Programming
    Replies: 8
    Last Post: 07-08-2002, 03:43 PM
  5. File Access with Strings and Numbers
    By Mace in forum C Programming
    Replies: 3
    Last Post: 12-01-2001, 03:07 AM

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