I am using this code to find the number between the parentheses in C++.
I want that number to be extracted out from a huge file which contain these type of data:
SUCCESSFUL CANDIDATES ARE INDICATED WITHIN PARANTHESIS AGAINST THEIR ROLL NUMBER AND THE EXTRA MARKS GIVEN [MAXIMUM FIVE MARKS] TO RAISE THEIR GRADES IN HARDSHIP CASES ARE INDICATED WITH PLUS[+] SIGN AND
GRACE MARKS CASES ARE INDICATED WITH CARET[+] SIGN
600023[545] 600024[554] 600031[605] 600052[560] ***********
Grade : D
Govt. Degree Boys College, Surjani Town
600060[877] *********** *********** *********** ***********
///// In the 2nd iteration when the [554] is found. the m.size() does not reset to zero that cause an error. How can i solve it? How i search it globally from the whole file the numbers in parenthesis [###]
#include <iostream>
#include <fstream>
#include <string>
#include<conio.h>
#include<regex>
using namespace std;
int main () {
ifstream myfile;
myfile.open("test.txt") ;
if(!myfile)
{
cout<<"The file you entered is not present"<<endl;
}
string str;
if(myfile.is_open())
cout<<"file is open";
else
cout<<"file is close";
string output;
regex e("\[(\d+)\]");
smatch m;
while (!myfile.eof()) {
myfile >> str;
cout<<"O="<<str<<endl;
bool match=regex_search(str,m,e);
cout<<"m.size() ="<<m.size()<<endl;
int n=0;
for( n=0;n<m.size();n++)
{
cout<<"m["<<n<<"] :str() =" <<m[n].str()<<endl;
}
}
getch();
myfile.close();
return 0;
}
Update: Now i am able to read the numbers.using string.
But my file is huge enough that Visual studio crashes.
I wanted a method that searches globally in a file.