Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jul 19th, 2006, 10:09 PM   #1
crawforddavid2006
Expert Programmer
 
crawforddavid2006's Avatar
 
Join Date: Apr 2005
Location: Not sure yet
Posts: 597
Rep Power: 0 crawforddavid2006 is an unknown quantity at this point
Send a message via AIM to crawforddavid2006 Send a message via MSN to crawforddavid2006
parseString

Does anyone know if there is a parseString method in C++? If so could you please show me how to use it too. Thanks
__________________
Quote:
Originally Posted by DaWei View Post
Well, it's better than Pen Islands url....;)

crawforddavid2006 is offline   Reply With Quote
Old Jul 19th, 2006, 10:33 PM   #2
Prm753
Professional Programmer
 
Prm753's Avatar
 
Join Date: Oct 2005
Location: United States
Posts: 447
Rep Power: 4 Prm753 is on a distinguished road
Send a message via AIM to Prm753 Send a message via MSN to Prm753
Perhaps this will help? http://www.harding.edu/USER/fmccown/...p_strings.html
__________________
The world's first athletic computer geek!
The home of PrProgramsStudios
How not to post a question: <-- Please don't reply
Prm753 is offline   Reply With Quote
Old Jul 19th, 2006, 10:42 PM   #3
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
You should bear in mind that C/C++ are relatively strongly typed. A C-string is an array of char. A C++ string is a string object. An int is an int. Aside from any adaptive objects you might create, or aside from making a relatively straightforward conversion (as int to float), everything else is essentially caused by you and healed by you.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Jul 20th, 2006, 4:36 PM   #4
crawforddavid2006
Expert Programmer
 
crawforddavid2006's Avatar
 
Join Date: Apr 2005
Location: Not sure yet
Posts: 597
Rep Power: 0 crawforddavid2006 is an unknown quantity at this point
Send a message via AIM to crawforddavid2006 Send a message via MSN to crawforddavid2006
what i'm trying to do is run a loop that will generate numbers from 1 to 50 lets say and then concatinate that number with a string but it won't let me do that since it is a number and string.
__________________
Quote:
Originally Posted by DaWei View Post
Well, it's better than Pen Islands url....;)

crawforddavid2006 is offline   Reply With Quote
Old Jul 20th, 2006, 4:49 PM   #5
coldDeath
Expert Programmer
 
coldDeath's Avatar
 
Join Date: Aug 2005
Location: UK
Posts: 862
Rep Power: 4 coldDeath is on a distinguished road
Send a message via AIM to coldDeath Send a message via Yahoo to coldDeath
Can't you convert your number type into a string type before concatination?
__________________
Join us at #programmingforums @ irc.freenode.net!

My software never has bugs. It just develops random features.
coldDeath is offline   Reply With Quote
Old Jul 20th, 2006, 5:03 PM   #6
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
You didn't indicate whether you were working with ANSI strings or C strings (arrays of char). If this is the wrong one, you can use it as a guide to convert, or post back.
#include <iostream>
#include <string>

using std::cout;
using std::endl;
using std::cin;

int main (int argc, char *argv[])
{
   char theBaseString [] = "Base + ";
   char theCombination [256] = "";

   for (int i = 0; i < 20; ++i)
   {
	sprintf (theCombination, "%s%d", theBaseString, i);
	cout << theCombination << endl;
   }
    cin.get ();
    return 0;
}
Quote:
Originally Posted by The Output
Base + 0
Base + 1
Base + 2
Base + 3
Base + 4
Base + 5
Base + 6
Base + 7
Base + 8
Base + 9
Base + 10
Base + 11
Base + 12
Base + 13
Base + 14
Base + 15
Base + 16
Base + 17
Base + 18
Base + 19
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Jul 20th, 2006, 5:26 PM   #7
Game_Ender
Professional Programmer
 
Game_Ender's Avatar
 
Join Date: May 2006
Location: Maryland, USA
Posts: 306
Rep Power: 3 Game_Ender is on a distinguished road
You can also use string streams and c++ strings and not worry about that unsafe sprintf. Well its not unsafe in this context, but in general you should use snprintf when available.

c Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. #include <sstream>
  3.  
  4. int main()
  5. {
  6. std::string base("Base + ");
  7. std::string result;
  8.  
  9. for(int i = 0; i <= 20; ++i)
  10. {
  11. std::ostringstream ss;
  12. ss << base << i;
  13. result = ss.str();
  14. std::cout << result << std::endl;
  15. }
  16.  
  17. cin.get();
  18. return 0;
  19. }
Game_Ender is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 8:57 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC