Skip to content

Instantly share code, notes, and snippets.

@adrian17
Created April 5, 2017 21:21
Show Gist options
  • Save adrian17/d457c1110dadad58b9b2f084d8e58799 to your computer and use it in GitHub Desktop.
Save adrian17/d457c1110dadad58b9b2f084d8e58799 to your computer and use it in GitHub Desktop.
#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