Answers for "c++ split vector by value"

C++
0

split string on character vector C++

string s, tmp; 
stringstream ss(s);
vector<string> words;

// If there is one element (so komma) then push the whole string
if(getline(ss, tmp, ',').fail()) {
  words.push_back(s);
}
while(getline(ss, tmp, ',')){
    words.push_back(tmp);
}
Posted by: Guest on October-15-2020
0

Split a number and store it in vector

#include <bits/stdc++.h>
using namespace std;
main() {
	int n = 1213456;
	vector<int> v;
	for(; n; n/=10)
  		v.push_back( n%10 );
	reverse(v.begin(), v.end());
	for (auto &i : v) cout<<i;
}
Posted by: Guest on March-27-2021

Browse Popular Code Answers by Language