locked
how to concate string and integer in vc++\c++ RRS feed

  • Question

  • hi friends,

              Has i am capturing the screen i need to store it . for eg:image1.jpg . I need to concat image and 1 that is string and integer . so pls help in this :
    Tuesday, February 9, 2010 4:54 AM

Answers

  • If I understand you correctly, you simply need to convert the integer to a string first, and then concatenate the result to the first string.

    strcat() and _itoa_s() should do the trick.

    If your string type is std::string instead of char*, then you can code something like:

    char buff[20];
    std::string a ("The number is ");
    int b = 2000;
    _itoa_s (b, buff, sizeof (buff) / sizeof (char), 10);
    a += buff;

    • Proposed as answer by Nikita Leontiev Tuesday, February 9, 2010 11:01 AM
    • Marked as answer by Nancy Shao Tuesday, February 16, 2010 7:16 AM
    Tuesday, February 9, 2010 4:59 AM

All replies

  • If I understand you correctly, you simply need to convert the integer to a string first, and then concatenate the result to the first string.

    strcat() and _itoa_s() should do the trick.

    If your string type is std::string instead of char*, then you can code something like:

    char buff[20];
    std::string a ("The number is ");
    int b = 2000;
    _itoa_s (b, buff, sizeof (buff) / sizeof (char), 10);
    a += buff;

    • Proposed as answer by Nikita Leontiev Tuesday, February 9, 2010 11:01 AM
    • Marked as answer by Nancy Shao Tuesday, February 16, 2010 7:16 AM
    Tuesday, February 9, 2010 4:59 AM
  • hi brian ,

    thanks for u r reply man , i got it  right....................
    Tuesday, February 9, 2010 5:10 AM
  • hi brian ,


                    i need an other help ; can u help me by giving  an code for loading bmp and save it as jpeg pls.....
    i have try'ed several code but i cant get it right ! so pls help me ..
    Tuesday, February 9, 2010 5:43 AM
  • Use CString's Format()

    example.

    int iFileCount = 1;

    CString strFileName;
    strFileName.Format("image%d.jpg",iFileCount);

    //some operation

    iFileCount++; // For next file name
    Knowledge is like light; It spreads only when you have clear and transparent mind. - Sreedhar
    Tuesday, February 9, 2010 7:38 AM
  • Use CString's Format()

    example.

    int iFileCount = 1;

    CString strFileName;
    strFileName.Format("image%d.jpg",iFileCount);



    The string literal should be decorated with _T() or TEXT(), so the code can be built in Unicode as well:

      strFileName.Format( _T("image%d.jpg"), iFileCount );


    Giovanni


    Tuesday, February 9, 2010 9:19 AM
  • ; can u help me by giving  an code for loading bmp and save it as jpeg pls.....

    You may want to consider CxImage class from CodeProject.


    Tuesday, February 9, 2010 9:20 AM