What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » C++ help :P

C++ help :P
Author: Message:
leito
Senior Member
****

Avatar
Chameleon by KeyStorm

Posts: 720
Reputation: 5
38 / Male / –
Joined: Apr 2003
O.P. Tongue  C++ help :P
Hey guys, I really need your help with this. I want to concatenate 1,2...n to a string with this...

            for (int i = 1; i<=n; i++){
                s+= i;
                s+= ",";
            }

But it just don't work, I think I have to converto from int to string, but I can't find a good way... :D

Thank you in advance for your help! I'll really appreciated, cuz I'm tired of this program.
[Image: leonelgalan.png]
08-13-2005 11:08 PM
Profile E-Mail PM Find Quote Report
TheBlasphemer
Senior Member
****

Avatar

Posts: 714
Reputation: 47
36 / – / –
Joined: Mar 2004
RE: C++ help :P
First of all, what is s ?
a string? or a char *?
Furthermore, a variable definition in a for loop isn't valid C++ either (although it will compile)

string s;
int i;
int n=100;
for (i=1; i<=n; i++) {
  stringstream ss;
  i>>ss;
  s<<ss;
  s+=",";
}

I *think* that might work, although I don't really use those std things a lot ;)
[Image: theblasp.png]
08-13-2005 11:31 PM
Profile PM Find Quote Report
leito
Senior Member
****

Avatar
Chameleon by KeyStorm

Posts: 720
Reputation: 5
38 / Male / –
Joined: Apr 2003
O.P. RE: C++ help :P
Ok, It work, thanks. I did a method that changes it int to string.

#include <string>
#incluce <sstream>

std::string Extras::intToString(int n){
    std::string s;
    std::stringstream ss;
    ss << n;
    s = ss.str();
    return s;

}

This post was edited on 08-14-2005 at 01:04 AM by leito.
[Image: leonelgalan.png]
08-14-2005 01:04 AM
Profile E-Mail PM Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On