Dec 17, 2018 at 10:22am UTC
Hi,
I have a file of 1gb, I'm searching for the term "topics" in it, after finding the search term I want to write that particular sentence (where "topics" present) into another file
Dec 17, 2018 at 11:45am UTC
So what's the problem?
- Can you open a file using ifstream?
- Can you read lines from the file using fstream::getline?
- Can you search a string using string::find ?
Dec 17, 2018 at 1:40pm UTC
yes, i can able to do all the above.
My problem is,
e.g., I'm searching for "topics", after finding I want to write the text after topics like "QC Physics","QD Chemistry","QH301 Biology" to another file.
It seems like following in my json file.
"topics":["QC Physics","QD Chemistry","QH301 Biology"]
Dec 22, 2018 at 2:10pm UTC
May I know what is " R"****"? Because I'm getting error (expected a ')' )
Dec 22, 2018 at 7:11pm UTC
// Json_Parsing.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "fstream"
#include <string>
#include "iostream"
#include "regex"
using namespace std;
string p;
string line;
int _tmain(int argc, _TCHAR* argv[])
{
int count = 0;
ifstream file;
file.open("F://project//DataSet//107.json",ios::in);
ofstream outfile,outfileTopics;
outfile.open("F://project//DataSet//107_New.json");
outfileTopics.open("F://project//DataSet//107_Topics.txt");
cout << "Reading successful"<<endl;
if(file.is_open())
{
while(!file.eof())
{
getline(file,line);
count++;
//cout << "no.of lines" << count <<endl;
if(p.find("fullText"))
{
if (p.find("topics"))
{
smatch m;
regex e("(\s(topics)*:*\[*(\w)*\]*\,)*");
if(regex_search(line,m,e))
{
for(int i=0;i<=count;i++)
{
cout << m[i].str();
outfileTopics << m[i].str() << endl;
outfile << line << endl;
}
cout << "writing sucessfull" <<endl;
}
}
}
}
}
}
I'm using the above code, but, i'm not getting any string in m[i]...sorry, to bother you...I'm new to c++ n i'm getting many doubts