my question is about this: I have some problems with my logic. I already detect when it have a parenthesis, but now I need to find numbers and know how many times they repeat in the txt file. This is my txt file:
(Visual basic)
(Llorente)
(Porto, 2008)
(Sommerville, 2010)
References
Visual Basic. (s.f.). Navarra.
Llorente, P.B. (s.f.). Fortran.
Porto, J.P. (2008)
Sommerville, I. (2010). Software Engineering. Unite Kingdom: Pearson.
The result should be: year : 2008 - 2 times, year : 2010 - 2 times, etc. PD: thanks I'm very noob.
#include <regex>
#include <iostream>
#include <fstream>
#include <map>
//33
int main()
{
std::ifstream readStream("references.txt");
std::map<int, int> cMap;
std::string input;
std::regex reg(R"(\([a-zA-Z\s]*,?\s*([0-9]+)\))");
std::regex inte("(\\+|-)?[[:digit:]]+");
///333
while (std::getline(readStream, input)) {
std::match_results < std::string::const_iterator > m;
if ((std::regex_search(input, m, reg)) ) {
int year = std::stoi(m[1]);
auto value = cMap.find(year);
if (value != cMap.end()) {
cMap[value->first] = value->second + 1;
} else {
cMap[year] = 1;
}
}
}
//33
for (auto x : cMap) {
std::cout << "year " << x.first << " is - " << x.second << " times." << std::endl;
}
//3
return 0;
}