Created
April 5, 2017 21:21
-
-
Save adrian17/d457c1110dadad58b9b2f084d8e58799 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <regex> | |
int main() { | |
std::regex pattern(R"((\d+) #(.+)# (\d+) ([\d.]+))"); | |
std::string line = "83 #Electric Sander# 7 57.00"; | |
// imagine that's inside the while() loop | |
std::smatch match; | |
std::regex_match(line, match, pattern); | |
int number = std::stoi(match[1]); | |
std::string name = match[2]; | |
int quantity = std::stoi(match[3]); | |
double price = std::stod(match[4]); | |
std::cout << number << '\n' << name << '\n' << quantity << '\n' << price << '\n'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment