![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Here's a way; there are others (one might break the line into string tokens using find, then convert);
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
using std::stringstream;
using std::string;
using std::vector;
using std::cin;
using std::cout;
using std::endl;
int main ()
{
vector <int> theTokens;
int aToken;
string testString = "098|87|94|101|108|115|122|129|136|143|150|157|164|171|178|185|192|199|206|213|220|227|234|241|248";
size_t start = 0;
size_t end;
while (true)
{
end = testString.find ("|", start);
if (end == string::npos) break;
testString.replace (end, 1, " ");
start = end+1;
}
stringstream theStuff (testString);
while (theStuff.good ())
{
theStuff >> aToken;
theTokens.push_back (aToken);
}
for (unsigned i = 0; i < theTokens.size (); ++i)
cout << theTokens [i] << endl;
return 0;
}
__________________
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 |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| VB Phone Number to Name... | NDawg28 | Visual Basic | 9 | Mar 10th, 2007 9:40 PM |
| Assigning an array of lists | deanosrs | C | 42 | Apr 13th, 2006 1:35 PM |