Below is my code;
int main(){
ifstream infile;
infile.open(fin);
ofstream outfile;
outfile.open(fout);
char c;
int input_order = 0;
string comp_str = "";
vector <string> pfx_str;
srand(time(NULL));
if (infile.fail())
{
cout << "cannot open file!" << endl;
return 0;
}
while (!infile.fail())
{
cout << input_order << endl;
c = infile.get();
if (c == '\n')
{
if (strcmp(comp_str.c_str(), "") != 0)
{
pfx_str.push_back(comp_str);
}
int num = rand() % pfx_str.size();
while (num == 0)
{
num = rand() % pfx_str.size();
}
for (int i = 0; i < num; i++)
{
outfile << "/" << pfx_str.at(i);
}
outfile << "\n";
input_order++;
pfx_str.clear();
}
else if (c == '/')
{
if (comp_str != "")
{
pfx_str.push_back(comp_str);
}
comp_str = "";
}
else
{
comp_str = comp_str + c;
}
}
infile.close();
outfile.close();
return 0;
}
For small set which consist of 10k inputs, it works.
However, for big set such as using 1600k inputs, it prints out 00000, and does not work. What makes it happened? and how to make it correctly working?
(Previously, I used this code for 1600k input and it works correctly....)
In compile, I used g++ -std=gnu++0x ....
.
I googled this issue but could not find out the right answer.. And also I could not figure out what this issue comes from....
Thanks,
+ This code is for randomly cutting the input.
This is the example of 1 input set; (to show the input pattern) /aa/ab/bc/aaa/ Here, I consider 'aa', 'ab', 'bc', and 'aaa' as one component. And I want randomly cut this input as components unit. this is the brief step of the code; 1. generate the random number(except 0) 2. ex) I use the above input and the random number is 2. then I cut this input and only '2' components is left, which is /aa/ab/ (repeat this procedure for each inputs in input text file
=> this input; /aa/ab/bc/aaa/ (inside, it generate random number 2) output to be printed in output file; /aa/ab/