Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

I had to write some code like this before and found a question on Stack Overflow for splitting a string by delimiter. Here's the original question: linklink.

You could use this with std::stoi for building the vector.

std::vector<int> split(const std::string &s, char delim) { std::vector<int> elems; std::stringstream ss(s); std::string number; while(std::getline(ss, number, delim)) { elems.push_back(std::stoi(number)); } return elems; } // use with: const std::string numbers("102:330:3133:76531:451:000:12:44412"); std::vector<int> numbers = split(numbers, ':'); 

Here is a working ideone sample.

I had to write some code like this before and found a question on Stack Overflow for splitting a string by delimiter. Here's the original question: link.

You could use this with std::stoi for building the vector.

std::vector<int> split(const std::string &s, char delim) { std::vector<int> elems; std::stringstream ss(s); std::string number; while(std::getline(ss, number, delim)) { elems.push_back(std::stoi(number)); } return elems; } // use with: const std::string numbers("102:330:3133:76531:451:000:12:44412"); std::vector<int> numbers = split(numbers, ':'); 

Here is a working ideone sample.

I had to write some code like this before and found a question on Stack Overflow for splitting a string by delimiter. Here's the original question: link.

You could use this with std::stoi for building the vector.

std::vector<int> split(const std::string &s, char delim) { std::vector<int> elems; std::stringstream ss(s); std::string number; while(std::getline(ss, number, delim)) { elems.push_back(std::stoi(number)); } return elems; } // use with: const std::string numbers("102:330:3133:76531:451:000:12:44412"); std::vector<int> numbers = split(numbers, ':'); 

Here is a working ideone sample.

added 255 characters in body
Source Link
Lander
  • 3.5k
  • 3
  • 41
  • 54

I had to write some code like this before and found a question on Stack Overflow for splitting a string by delimiter. Here's the original question: link, and.

You could use this with std::stoi for building the code I modified:vector.

voidstd::vector<int> split(const std::string &s, char delim,) {  std::vector<std::string> &elems)vector<int> {elems; std::stringstream ss(s); std::string item;number; while(std::getline(ss, itemnumber, delim)) { elems.push_back(itemstd::stoi(number)); } } 

You could use this with std::stoi for building the array.

void split(const std::string &s, char delim, std::vector<int> &elems)return {elems;  } // use with: const std::stringstreamstring ssnumbers(s"102:330:3133:76531:451:000:12:44412");  std::string number; vector<int> numbers = while(std::getlinesplit(ss, itemnumbers, delim)) {  elems.push_back(std:':stoi(item)'); } } 

Here is a working ideone sample.

I had to write some code like this before and found a question on Stack Overflow for splitting a string by delimiter. Here's the original question: link, and the code I modified:

void split(const std::string &s, char delim, std::vector<std::string> &elems) { std::stringstream ss(s); std::string item; while(std::getline(ss, item, delim)) { elems.push_back(item); } } 

You could use this with std::stoi for building the array.

void split(const std::string &s, char delim, std::vector<int> &elems) {   std::stringstream ss(s);  std::string number;  while(std::getline(ss, item, delim)) {  elems.push_back(std::stoi(item)); } } 

I had to write some code like this before and found a question on Stack Overflow for splitting a string by delimiter. Here's the original question: link.

You could use this with std::stoi for building the vector.

std::vector<int> split(const std::string &s, char delim) {  std::vector<int> elems; std::stringstream ss(s); std::string number; while(std::getline(ss, number, delim)) { elems.push_back(std::stoi(number)); } return elems; } // use with: const std::string numbers("102:330:3133:76531:451:000:12:44412"); std::vector<int> numbers = split(numbers, ':'); 

Here is a working ideone sample.

Source Link
Lander
  • 3.5k
  • 3
  • 41
  • 54

I had to write some code like this before and found a question on Stack Overflow for splitting a string by delimiter. Here's the original question: link, and the code I modified:

void split(const std::string &s, char delim, std::vector<std::string> &elems) { std::stringstream ss(s); std::string item; while(std::getline(ss, item, delim)) { elems.push_back(item); } } 

You could use this with std::stoi for building the array.

void split(const std::string &s, char delim, std::vector<int> &elems) { std::stringstream ss(s); std::string number; while(std::getline(ss, item, delim)) { elems.push_back(std::stoi(item)); } }