Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
#include <iostream>
#include <sstream>
#include <algorithm>
double unformatData(std::string unformattedString); // prototype
int main() {
std::cout << "Hello, World!" << std::endl;
std::string inputString = "47,001;122,234;0,9999";
std::cout << inputString << std::endl;
std::cout << "break on semicolons" << std::endl;
std::stringstream ss(inputString);
std::string token1;
getline(ss, token1, ';');
std::string token2;
getline(ss, token2, ';');
std::string token3;
getline(ss, token3, ';');
std::cout << "token1: " << token1 << std::endl;
std::cout << "token2: " << token2 << std::endl;
std::cout << "token3: " << token3 << std::endl;
double answer1 = unformatData(token1);
double answer2 = unformatData(token2);
double answer3 = unformatData(token3);
std::cout << "answer1: " << answer1 + 1 << std::endl;
std::cout << "answer2: " << answer2 << std::endl;
std::cout << "answer3: " << answer3 << std::endl;
return 0;
}
double unformatData(std::string unformattedString) { // define
std::stringstream ss(unformattedString);
std::string s = ss.str();
std::replace(s.begin(), s.end(), ',', '.');
ss.str(s);
//std::cout << ss.str() << std::endl;
double answer;
ss >> answer;
//std::cout << answer << std::endl;
return answer;
}