Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- void split(std::vector<std::string> &ret, std::string source, std::string delimiter) {
- std::vector<std::string> tmp;
- size_t start = 0, end = 0;
- while((end = source.find(delimiter, start)) != std::string::npos) {
- tmp.push_back(source.substr(start, end - start));
- start = end + 1;
- }
- tmp.push_back(source.substr(start, source.length()));
- ret = tmp;
- return;
- }
- void split(std::vector<int> &ret, std::string source, std::string delimiter) {
- std::vector<int> tmp;
- size_t start = 0, end = 0;
- while((end = source.find(delimiter, start)) != std::string::npos) {
- tmp.push_back(std::stoi(source.substr(start, end - start)));
- start = end + 1;
- }
- tmp.push_back(std::stoi(source.substr(start, source.length())));
- ret = tmp;
- return;
- }
- void split(std::vector<float> &ret, std::string source, std::string delimiter) {
- std::vector<float> tmp;
- size_t start = 0, end = 0;
- while((end = source.find(delimiter, start)) != std::string::npos) {
- tmp.push_back(std::stof(source.substr(start, end - start)));
- start = end + 1;
- }
- tmp.push_back(std::stof(source.substr(start, source.length())));
- ret = tmp;
- return;
- }
- int main() {
- std::vector<float> d;
- split(d, "5.4 6.5 7.6", " ");
- for(int z=0; z!=d.size(); z++) {
- std::cout << d.at(z)*d.at(z) << std::endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement