Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Question on String manipulation

Posted on 1998-11-07
1
Medium Priority
?
224 Views
Last Modified: 2013-11-20
Hi,
     I'll illustrate my problem with a program segment.
---------------
int total=100;
CString str = "There are altogether ", str2;

//my intention is to combine the string which will appear
//like this: "There are altogether 100 cats!"
str2 = str + total + " cats!"; // this is improper!
MessageBox(str2);
--------------------------------
My question is how can I combine the whole thing above to have a message which says "There are altogether 100 cats!"?

For your informations, I'm writing my programs using MSVC 5.0, a dialog-based program and working on win98 platform.

Any help offered is very much appreciated!
0
Comment
Question by:justinng
1 Comment
 
LVL 23

Accepted Solution

by:
chensu earned 80 total points
ID: 1324328
Replace
str2 = str + total + " cats!";
with
str2.Format("%s%d%s", str, total, " cats!");
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Integration Management Part 2
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question