Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#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
You can’t perform that action at this time.