ClanKiller.com http://forums.clankiller.com/ |
|
C++ and stuff http://forums.clankiller.com/viewtopic.php?f=24&t=1267 |
Page 1 of 1 |
Author: | Satis [ Mon Jun 06, 2005 3:55 pm ] | ||||||||||||||||||||||||||||||||||||
Post subject: | C++ and stuff | ||||||||||||||||||||||||||||||||||||
ok, well, now I have more questions. I've searched online and can't find the answer. Spoke with some friends of mine who took c++ once (a long time ago, in a galaxy far, far away) and they can't remember. When you open a file, you use a file handle, a la:
In this case, my file handle is 'filelist'. I can close the file:
but, if I try to open another file using the same handle later on, I get an error.
which implies you can't reuse file handles. This can't be right. There's probably some way to clear the handle entirely so you can reuse it. Anyone know how the hell to do that? also, I have a question about parsing an input..... let's say I have a variable along the lines for "blah, blah blah blah, etc etc, blah" and I want to parse it into an array broken up on the commas. In php, I'd just $thevariable = explode(",",$thevariable). What's the best way of doing this in c++? I hacked together a way of parsing it using .find and .substr, but it's not very pretty. However, it does work. Any pointers? completed code: (an example line from the file would be 'afilename.asp,c:\program files\etc').
|
Author: | RB [ Tue Jun 07, 2005 8:25 am ] | ||||||||||||||||||
Post subject: | |||||||||||||||||||
One example for reuse of a stream.
The error you get imply that you are trying not just to reuse the stream, but as well to create it again. That is no-no because it alredy exist. I have marked the keyrows with comments. The first, which close the file clear the stream but it is not really ready for the use if its past resource reached EOF or got some error. You have to reset the flags of the stream with the method clear. Then it is as totaly new one and ready for use. You can use the method open to open the new file. It can be noted that ifstream in("abc"); and ifstream in; in.open("abc") will give the same result. Now on the parsing. Well, let this be one solution. I hope you do well with the vector template. This is NOT the best solution but it is simplest coming to the mind. Ok?
Function F solve your problem, I belive. Arguments are the filename, char which is parsesymbol and the reference to the vector<string> resource. Just take care that variable maxwordsize be greater than the longest string to be parsed out. |
Author: | Satis [ Tue Jun 07, 2005 11:05 am ] |
Post subject: | |
thanks gfree. The file thing makes total sense to me, good work explaining it. The other thing I'll need to pull apart and analyze for a bit, but I think I understand what's going on. If I have any more questions, I'll let you know. |
Page 1 of 1 | All times are UTC - 6 hours |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |