473,385 Members | 2,180 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Building integer into a string

Hi, this is one of the questions from Bruce Ekels thinking in C++
book, chapter 12, question 14, i have only posted the first part of
the question that i am stuck with.

How do you combine an integer into the string class in C++?

Write a class called Bird that contains a string member and a static
int. In the default constructor, use the int to automatically generate
an identifier that you build in the string, along with the name of the
class (Bird #1, Bird #2, etc.).

Thanks

Aug 22 '07 #1
1 2008
On Aug 22, 1:24 pm, dev_15 <naumansulai...@googlemail.comwrote:
Hi, this is one of the questions from Bruce Ekels thinking in C++
book, chapter 12, question 14, i have only posted the first part of
the question that i am stuck with.

How do you combine an integer into the string class in C++?

Write a class called Bird that contains a string member and a static
int. In the default constructor, use the int to automatically generate
an identifier that you build in the string, along with the name of the
class (Bird #1, Bird #2, etc.).

Thanks
use stringstream ($include <sstream>)

//sample code
class Bird
{
private:
string name;
static int cnt;
public:
Bird()
{
stringstream ss;
ss << cnt;
name = "Bird#" + ss.str();
cnt++;
}
};

-N
int Bird::cnt = 1;

Aug 22 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: sparks | last post by:
I know this is a stupid question but I can't find the answer. Please tell me where to find reference to this so I can print it out and staple it to my head.. dim I as integer dim missedstr as...
6
by: Ian Gibbons | last post by:
Firstly what type is %x as I've not encountered it before? Now the problem: I'm trying to alter a host masking system for ircd so that it masks all but the isp name and location (if .uk.us etc..)....
6
by: Dennis | last post by:
I was trying to determine the fastest way to build a byte array from components where the size of the individual components varied depending on the user's input. I tried three classes I built: (1)...
8
by: Jacob Arthur | last post by:
How would I go about using a custom select string that is passed from a form to the SelectCommand parameter of SqlDataSource? I tried: SelectCommand = "<% Request.Form("hdnSelect") %>" but I...
9
by: DFS | last post by:
You might also find other uses ========================================================= Public Function getSelections(selType As String, selSeparator As Boolean, selList As ListBox, selCol As...
13
by: royaltiger | last post by:
I am trying to copy the inventory database in Building Access Applications by John L Viescas but when i try to run the database i get an error in the orders form when i click on the allocate...
2
by: ILCSP | last post by:
Hi, I have a sql table containing the answers for some tests. The information in this table is presented vertically and I need to create strings with them. I know how to read the data in VB.Net...
1
by: dileepd | last post by:
Hi Every one, Could you please let me know if you have any clue about following things. 1. Whether type bool acts like a kind of signed int type in g++ on solaris 9(a/c to my invetsigation it...
3
by: bernd | last post by:
Hi folks, the code below "runs" with the following message: Before structure assignment Bus Error(coredump) What I am trying to do is to define an "outer" structure containing an inner one...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.