for(x = 0;x<number;x++,y++)
{
//Writing the file names
ostringstream child_file;
string in_text,final_text;
int startp,endp,p_endp,last_char,p_last_char;
startp = 4096 * x;endp = 4096 * y;p_endp = 4096 * (y-1);
child_file << std_name << " Pt " << y << ".txt";
child_name = child_file.str();
fout.open(child_name.c_str());
if(fexists(child_name.c_str()) == false)
{
cout << "\nIn file " << child_name.c_str() << "\n";
cout << "Error: file unable to be made correctly\n";
pause();
return 1;
}
//Writing the file content
fin.open(File_name_opened.c_str());
in_text = fin._Stdstr;
//endpoint of previous iteration
p_last_char = in_text.rfind('.',p_endp);
if(p_last_char < 0){p_last_char = 0;}
//endpoint of this iteration
last_char = in_text.rfind('.',endp);
//what should go in the file
final_text = in_text.substr(p_last_char,last_char);
fout << final_text;
fin.close();
fout.close();
}
what i want to happen is similar to the split function, but ending at the last period. What is happening is that i get a space in each file and nothing more. I believe it has to do with the initialization of in_text not being equal to the data inside the document. How can i make it equal to said data?
line 21 was my pathetic attempt at trying to find a solution to my problem. It didn't work.
fexists() was a function i defined earlier that returns a bool value, which works pretty much as you said, i added the line so it's a little easier to read (imo).
no i probably don't. i wasn't sure how it would effect in_text, and considering there were problems not opening and closing fout, i did it to be safe temporarily (as it is a waste of energy and time to keep it there if i don't need it to be there, as you said).
though i'm unsure of what you mean by "magic number" i could technically avoid p_endp because using rfind('.',startp) would technically be the same. But again this is for readability on my part.
Though i do appreciate your help, you did not make any mention of what in_text is equal to, or how to make it equal to the data inside the document. Is this because you don't know, or that i'm asking the wrong question? (no intended offense of course, i really do appreciate all the help i get on this site)
in_text = fin._Stdstr; what will contain in_text after? (one word, one line, all the file ? )
If you want to dump all the data from the file to the string you can use
I wouldn't think in_text would need to be contained or pointed to.
in_text should be the whole file
4096 characters is equal to 4 kb of data, which is exactly what i'm trying to get.
what is aux in your example code?
the file is a book written to a txt file. There will be multiple new line characters, so using getline, at least as i understand it in your code, won't work will it?
4096 characters is equal to 4 kb of data, which is exactly what i'm trying to get.
1 2 3 4 5
//getting a block of 4Kb
const in size = 4096;
char buffer[size]; //or char buffer[size+1] so you can end with '\0'
fin.open( filename, ios::binary );
fin.read( buffer, size );
the file is a book written to a txt file. There will be multiple new line characters, so using getline, at least as i understand it in your code, won't work will it?
The idea is to get a line, that I will know that ends with new line or it reaches the end of file. And just keep appending every line with a "\n" at the end. So in_text should have all the file in memory.