I am trying to make a simple program to try out some exporting to extrenal .txt files, but I'm encountering the R6010 error... I'm not very far into my studies of c++ but I've read through the tutorials on this site and understood most of it.
the errors started popping up when I started filling the letterpointer array
1 2 3 4 5 6
for (int n = 0; n < lengte; n++)
{
letterpointer[n] = ttext.substr(n, 1);
(stringstream)letterpointer[n] >> letter;
point[n] = letter;
}
(I forgot that earlier and had less problems then)
that helped slightly, but now I can't write spaces to the file and it gives a load of double lines in the output screen when I try to read it and when I go to look into the file after i've completed the program it contains the orriginal text and a load of ÌÌÌÌÌÌÌÌÌÌÌÌÌ(capital i with a little stripe to the left) and it writes over the orriginal text...
any help on that?
(I forgot to add this line and added that now: straempje.open("save_file.txt", fstream::in);)
getline(cin, ttext);
long lengte = sizeof(ttext);
char* point;
point = new (nothrow) char[lengte];
char letter;
string* letterpointer;
letterpointer = new (nothrow) string[lengte];
for (int n = 0; n < lengte; n++)
{
letterpointer[n] = ttext.substr(n, 1);
(stringstream)letterpointer[n] >> letter;
point[n] = letter;
}
streampje.write(point, lengte);
could be entirely replace by this:
1 2
getline(cin, ttext);
streampje << ttext;
But that's not your problem. The problem is that streams are buffered. The data is written to the buffer and only if the buffer is full or flush() is called (either explicit of implicit via endl or close()) the data is written to the disk. When you use another object (straempje) for reading the data you won't get what's currently in the buffer, hence you get garbage values.
thank you very much, that did fix the problem(except I had to put back the long lengte=sizeof(ttext)
because that is needed for the input array.
but now I have the next problem, the return value now only returns the first 28 characters but the output file does contain the entire text.
any help on that?
Yes, I am dyslectic, but I knew the difference here. I changed the name because otherwise it wouldn't really make sense. do you have to reopen a file in a specific mode after it has been created? or can you instantly start writing?
Because it gets rather irritating to have to write: