![]() |
| ||
| Easy help: Start and stop reading in the middle of a file I'm trying to make a program that will read names and numbers from a file, but I'm quite inexperienced in C++ in general, and most tutorials and help threads I read tend to make me confused. So far, I have used a test file with a text like "NameA 01234 NameB 11111 NameC 55555". I want the names in one string and the numbers in another one, which I have managed to do with the code: ifstream in("test.txt");My problem now is that the file I actually want to read from is more complicated, and looks more like: "LotsOfTextThat;IAmNotInterestedIn; MATRIXNameA 01234 NameB 11111 NameC 55555; MoreTextThatIsOfNoUse". In other words, I want to start reading after the word "MATRIX" and stop at the character ";". How do I edit my code to make it do that? |
| ||
| Re: Easy help: Start and stop reading in the middle of a file I just saw that I messed up a bit. The code was supposed to be like this: ifstream in("test.txt");and what I want to do is to start reading after the word "MATRIX" and stop before the character ";" |
| ||
| Re: Easy help: Start and stop reading in the middle of a file And Secondly. Why dont you just search for the word Matrix in Your File? string inName[3],inChar[3]; That way You will read the next words into strings |
| ||
| Re: Easy help: Start and stop reading in the middle of a file Well, that's just about the help I wanted :) As I said, my programming skills are not too great. After a while, I figured out that you must have meant "while(!in.eof())", and now my program works perfectly fine. Thanks! |
| All times are GMT -4. The time now is 9:02 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC