![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Expert Programmer
|
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
__________________
|
|
|
|
|
|
#2 |
|
Professional Programmer
|
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 |
|
|
|
|
|
#3 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#4 |
|
Expert Programmer
|
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.
__________________
|
|
|
|
|
|
#5 |
|
Expert Programmer
|
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.
|
|
|
|
|
|
#6 | |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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:
__________________
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 |
|
|
|
|
|
|
#7 |
|
Professional Programmer
Join Date: May 2006
Location: Maryland, USA
Posts: 306
Rep Power: 3
![]() |
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)
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|