473,320 Members | 1,881 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,320 software developers and data experts.

can string be a substitute of char s[] or char* s ?

Hi every one,

I am a newbie in C++ and have some experience in C.
My program always seems like a mixture of C and C++,
especially when dealing with string. sometimes I use
std::string but I have some difficult on controlling it
for example:
// format the string as what I like
sprintf(s, "%s%d",buf,i )

I don't know how to do it in std::string in C++

1. Any suggestion about what kind of material I should read
online or book will both be good.

another problem is when I use string under gcc 2.9.*
sometimes met compile error like
<char> ......(I don't remember clearly, but no such problem in
the newest gcc compiler)

so,

2. what about the different gcc version's support of c++ standard ?
Jul 22 '05 #1
4 1127

"Lingyun Yang" <yz***@insightbb.com> wrote in message
news:CeKdc.3021$rg5.28995@attbi_s52...
Hi every one,

I am a newbie in C++ and have some experience in C.
My program always seems like a mixture of C and C++,
especially when dealing with string. sometimes I use
std::string but I have some difficult on controlling it
for example:
// format the string as what I like
sprintf(s, "%s%d",buf,i )

I don't know how to do it in std::string in C++
One way is

ostringstream tmp;
tmp << buf << i;
string s = tmp.str();

Another way is to look at the format library from boost (www.boost.org)
which lets you do printf like formatting on strings.

1. Any suggestion about what kind of material I should read
online or book will both be good.
Depends on what you know already. I reckon Scott Meyers books Effective C++
and More Effective C++ might be good for you.

another problem is when I use string under gcc 2.9.*
sometimes met compile error like
<char> ......(I don't remember clearly, but no such problem in
the newest gcc compiler)

so,

2. what about the different gcc version's support of c++ standard ?


2.9 is not so good. 3.x is much better.

john
Jul 22 '05 #2

"Lingyun Yang" <yz***@insightbb.com> wrote in message
news:CeKdc.3021$rg5.28995@attbi_s52...
Hi every one,

I am a newbie in C++ and have some experience in C.
My program always seems like a mixture of C and C++,
especially when dealing with string. sometimes I use
std::string but I have some difficult on controlling it
for example:
// format the string as what I like
sprintf(s, "%s%d",buf,i )

I don't know how to do it in std::string in C++
One way is

ostringstream tmp;
tmp << buf << i;
string s = tmp.str();

Another way is to look at the format library from boost (www.boost.org)
which lets you do printf like formatting on strings.

1. Any suggestion about what kind of material I should read
online or book will both be good.
Depends on what you know already. I reckon Scott Meyers books Effective C++
and More Effective C++ might be good for you.

another problem is when I use string under gcc 2.9.*
sometimes met compile error like
<char> ......(I don't remember clearly, but no such problem in
the newest gcc compiler)

so,

2. what about the different gcc version's support of c++ standard ?


2.9 is not so good. 3.x is much better.

john
Jul 22 '05 #3
Lingyun Yang <yz***@insightbb.com> wrote:
I am a newbie in C++ and have some experience in C.
My program always seems like a mixture of C and C++,
especially when dealing with string. sometimes I use
std::string but I have some difficult on controlling it
for example:
// format the string as what I like
sprintf(s, "%s%d",buf,i )

I don't know how to do it in std::string in C++

1. Any suggestion about what kind of material I should read
online or book will both be good.


Accelerated C++ would probably be a good choice for you.
Jul 22 '05 #4
Lingyun Yang <yz***@insightbb.com> wrote:
I am a newbie in C++ and have some experience in C.
My program always seems like a mixture of C and C++,
especially when dealing with string. sometimes I use
std::string but I have some difficult on controlling it
for example:
// format the string as what I like
sprintf(s, "%s%d",buf,i )

I don't know how to do it in std::string in C++

1. Any suggestion about what kind of material I should read
online or book will both be good.


Accelerated C++ would probably be a good choice for you.
Jul 22 '05 #5

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

Similar topics

4
by: Lingyun Yang | last post by:
Hi every one, I am a newbie in C++ and have some experience in C. My program always seems like a mixture of C and C++, especially when dealing with string. sometimes I use std::string but I...
2
by: Michele Simionato | last post by:
This is somewhat in between a bug report and a feature request. I was using the new string.Template class and I have run into a few issues that I traced back to the usage of the idiom '%s' % val...
4
by: Joe H | last post by:
Hi i converted a program to a lib. The parameters of main are maincommand(int argc, char **argv) I want to use main a s function that takes a string how can i convert a char * to a char ** or even...
12
by: John Leslie | last post by:
I need to write a string to a file in EBCDIC. Do I need to do it character by character using a translation table, or is there a function to translate the whole string? (I am aware that I can...
35
by: Felix Kater | last post by:
The C-faq says that "The malloc/free implementation remembers the size of each block allocated and returned, so it is not necessary to remind it of the size when freeing." Could that length...
4
by: francescomoi | last post by:
Hi. I'm trying to remove some characters within a string and substitute others. For instance, I want to convert: John's new house, great ---> Johns-new-house-great I tried with:...
8
by: Jami Bradley | last post by:
Hi, I'm looking for an efficient way to do this, because I know it will be heavily used :-) I have a fixed width string and I need to substitute a substring of characters with new values. I...
4
by: yaru22 | last post by:
Hi, I'm relatively new to C programming and was quite confused by this error. What I tried to do is that if I have a string with double quotes around it (i.e. char *str = "\"hello\"";), I have...
10
by: Mo | last post by:
Hi, I am trying to write a code to build a string 768 characters long. This string is going to be written to a file which is then read by another application. The format of the string is already...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
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
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.