If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

c++ I/O problems

Hey, everyone! I need to read in a file, modify it, and then output it to another file. Then that file needs to be read in, modified, and then output to yet another file. The problem is that I cannot use the getline() function, because there may or may not be new lines in the 100 MB file. Here is what I have, but it does not work:

The first I/O section adds some characters to the end of the file, and the second ends up being an infinate loop because file_in.tellg() always equals -1. I am really lost, and I have been trying to do this for a few weeks, so any help would be great. Thanks.

stdlib and iostream...

First of all, why don't you include a library of some sort that your compiler provides? Such as iostream? It would be much easier to understand, for me, and maybe that will actually fix your problem. Try learning C. It is easier that C++ and you get to define everything on your own. By the way, use cout and cin for iostream. For cstdlib or stdlib, use printf("%s",char something="") and scanf("%s",char something=""). This may help you clarify the I/O part so that it is not self defined. As for the other part of your code, I do not understand what you are saying. Perhaps you could clarify your meaning.

First of all, why don't you include a library of some sort that your compiler provides? Such as iostream? It would be much easier to understand, for me, and maybe that will actually fix your problem.

I included iostream and fstream. The reason the rest of the code it not posted is for security purposes (I would like to share as little code as posible that does not directly pertain to the problem, but I should have included that information, so I apologise).

Try learning C. It is easier that C++ and you get to define everything on your own.

Thanks, but I think I'll stick with C++, since the program is done except for this problem.

By the way, use cout and cin for iostream. For cstdlib or stdlib, use printf("%s",char something="") and scanf("%s",char something=""). This may help you clarify the I/O part so that it is not self defined.

Sorry for my ignorance, but what? Since I am not really familiar with C or C++, that makes no sense.

As for the other part of your code, I do not understand what you are saying. Perhaps you could clarify your meaning.

What part are we talking about? I would be happy to clear anything up for you.

If it is easier than sorting through my horrible chunk of code, maybe you can give me an example of what I am trying to do? (beleive it or not, the rest of the looks good and readable )

Thanks for the reply, as well. I was wondering if anyone on DD knew anything about C++, lol.

I have a question. Where are the included libraries that will allow the I/O operations? If you have the COMPLETE CODE, please, let me see it. In order to actually help you with flying colors, I will need the whole code. Other than that, I do not know how the I/O operations work because there are no included libraries. Once again, in order to help you, I must see the complete code. Also, the getline() function may not work because it is included in a non-included file. Hopefully you reply.

Also, the getline() function may not work because it is included in a non-included file. Hopefully you reply.

I am not using that function. See the first post again:

The problem is that I cannot use the getline() function, because there may or may not be new lines in the 100 MB file.

The file is not likely to have new lines, because of the way it is generated (I won't go into that-- just trust me that there are few new lines, if any at all).

I am wondering, if it would be better just to ditch this code and start over. What do you suggest I do to accomplish what I need? (I need to read in 350 chars at a time to a string from a file, modify the string, insert it into another file, and to the same thing over again with the second file.)

It is actually all too confusing. The only way I can fix the script is if I have every single bit of code there is, just to understand it all (the code, that is). Alternatively, start over. I understand what the code is supposed to do, just not HOW it does it. If you could try to compile the code again and tell me the exact errors the compiler gives you, I may be able to understand what is wrong. All in all, starting over would be easiest. Three last things: One-Did you make the code? Two-Do you not want me to see the whole code because you are afraid of me stealing it (I WILL NOT STEAL THE CODE. HONEST.) Three-If it is VERY IMPORTANT, try to get it copyrighted.

It is actually all too confusing. The only way I can fix the script is if I have every single bit of code there is, just to understand it all (the code, that is). Alternatively, start over. I understand what the code is supposed to do, just not HOW it does it. If you could try to compile the code again and tell me the exact errors the compiler gives you, I may be able to understand what is wrong. All in all, starting over would be easiest.

Well, the rest of the code is only a class to modify the text input. There are also no compiler errors-- the problem is that the first block, namely this:

is an infinate loop for some reason. I agree that starting over is probably the best solution, but I have done that at least five times and I have no idea where to start. Do you have any suggestion?

Three last things: One-Did you make the code? Two-Do you not want me to see the whole code because you are afraid of me stealing it (I WILL NOT STEAL THE CODE. HONEST.) Three-If it is VERY IMPORTANT, try to get it copyrighted.

1) Yes, otherwise it would probably work 2) No, it's nothing like that. However, the software is for security purposes so I don't want to show it. And at any rate the class shouldn't be needed-- it's basically irrelevant to the problem. (When text is read in from a file, that class modifies it before sending it to the output file.) Without the file I/O, the class works perfectly. 3) It's not that important.

And one last thing: Are you a black belt??

Yes 3rd Dan in Tae Kwon Do.

Edit:In the second block, the reason for the infanite loop is that this line:

Code:

pos = file_in.tellg();

Always sets pos to-1 (thus pos - the file length is 1, which the loop thinks is another character to read in so the loop starts again), but I don't know why that is.