| |
| |
| |
|
Page: 1 2 3 4 5 6 7 8
Comments:
<0> could someone propose how i could test for the end of file with using the above? <0> ok found it, if anyone is interested you can use the peek method <1> uh, no <1> i told you <1> test your reading for failure <1> if( some_stream >> some_var ) { /*read success*/ } else { /*unsucessful*/ } <0> if i use read the help says that if an eof occurs the function calls setstate(failbit). But it doesn't say how i can check if it is set <1> what does read() return? <0> this <1> there ya go <0> *this in any case <1> if( thing.read( ... ) ){ /*read success*/ } else { /*unsucessful*/ } <1> .eof() exists in vc++2005 <0> for fstream it doesn't <1> it's part of the standard, i'm not sure why you think it 'doesn't exist' <1> yes it does
<0> try to type fstream mystream; mystream.eof() <1> std::fstream fs; fs.eof(); //compiles just fine <1> why are you using an fstream and not an ifstream / ofstream ? <0> because i don't know from the beginning what it will be <1> and you still didn't paste the error message, so *shrug* <1> irregardless <0> error C2039: '_eof' : is not a member of 'std::basic_fstream<_Elem,_Traits>' <1> check your read for success/failure <1> _eof ? <0> ok i tried also _eof <0> in the first i tried eof <1> you did include <fstream> right? <0> yes <1> shrug <1> maybe you messed up your include paths or something <0> i tried what you said about std::fstream fs; fs.eof; but it still doesn't exist, i get the same error <0> fresh installation <1> fs.eof(); <0> yes <1> well, it doesn't matter <1> eof() isn't used to determine if a read was successful or not <1> why are you using .read(), anyway? <1> what exactly are you reading? <0> what should i use? <1> depends on what you're reading <0> an ascii file <1> i mean, specifically what you're reading <1> what's in the file? <0> numbers,and some characters inbetween, it's like a coding so i check every character one by one <1> line by line, or do you read the entire file character by character? <0> character by char <0> is there a better way to read? <1> .get() gets a single character <1> although <1> character by character is horribly inefficient <1> I would read a bunch into a vector<char> and then do processing until you need more chars <1> how big is the file? <0> can be 400mb <1> k <1> then certainly read a bunch at a time <1> maybe a meg for a single read or so <1> character by character will crawl <0> you mean when i do the read(char, 1000) or something like that? <1> well <1> you can do this... <1> vector<char> buffer( 1000000 ); if( f.read( &buffer[0], buffer.size() ) ) { //process the data } else { //we can't read that much data.. buffer.resize(0); f.clear(); std::copy( std::istream_iterator<char>( f ), std::istream_iterator<char>(), std::back_inserter( buffer ) ); //process buffer.size() bytes of data } <1> I think that would work fine <1> when you hit the 'else' block there you can ***ume that it will be the last read done <0> well it's a nice idea you gave me, i think i will reconsider the way i thought about it <0> thanx for the help rdragon <1> sure thing <0> one thing i cannot seem to figure out is how to check read if it failed, i mean it says that in any case it returns *this and on eof it does setstate(failbit); <0> hmm i don't know what happened but now it recognises .fail(), ok forget about it <1> if( f.read(...) ) <1> that's how you check <1> just like if( cin >> some_var ){ ... } <0> although read fails, it stores what it read to the vector, is there a way to know how many elements of the vector are blank, or should i iterate throught it? <1> nope <1> thats what the else{ block handles in my code <0> what do you mean when you say process buffer.size()? <1> that tells you how much was read
<0> but when you resize the buffer you set it to zero, how will the next statement work? actually i tried it but probably the statement with the std::copy doesn't work <1> copy copies elements from the stream until it hits the end of stream <1> and it copies into the vector using the back_inserter <1> which will push_back() the elements into the vector <0> this means i should rewind the stream before doing the copy? <1> no <0> if i rewind it, it works, if i don't it stores nothing in the buffer, so i just use tellg() and seekg() and it works just fine:) <1> oh, shrug <0> it's ok, no worries, it works at the end:) <2> !seen Elmpie <2> o.o <3> http://www.lpboulder.com/quotes/ <4> Does any STL container allow for shifting an element to the end? <5> could you be a little more specific, what does "shift and element to the end" mean? <6> I think he's refering about rotating the collection <5> threat ??? you gonna answer or are we supposed to sit around all night guessing what you want <4> vawjr, back <5> so what's the actual problem? <4> vawjr, what I want to do is insert int's in to a container (no great than a 1000). If an int being inserted is the same as an int already inthe container then I dont want to add the int in but instead shift / move the int inside the container so I have all of the mostly inserted values at one end and the least inserted at the other <4> eg I insert 2, 3, 4, 5, 2, 4, 6, 7, inside the container I should have something like 2, 4, 3, 5, 6, 7 <5> <shrug> ok <7> std::set, kthx <4> yes, dont ask me why I want this :) I just do <7> use std::set, that is <5> no <4> Cowmoo, yes but doesnt a set sort it? <5> that will leave them sorted <7> isn't that what you want? <7> eer <5> NO <4> Cowmoo, I want it sorted to some extend, but I dont want it sorted on the value of the int <7> looks like I miunderstood you.. <4> Cowmoo, I want it sorted based on how many of the same value has been inserted <4> Cowmoo, like my example I gave above :) <7> iohhh <7> k <8> can someone help me with a sipmle rectangle program thing? my rectangle isn't printing out right <5> and yes you can rotate the sequence containers <4> Cowmoo, inserting 3, 8, 9, 2, 5, 2, 1, 2, 3 should result in 2, 3, 8, 9, 5, 1 or something simular <7> right <8> http://rewtguy.sweon.net/programming/c++/code/rectangle.cpp <4> vawjr, ok, so I can shift things around within, say, a vector? <6> don't use a vector for this thing <6> a list <4> ok <4> I will use a list <7> no <5> threat, of course.... sounds like you need book on the library <6> tho, I don't know how to shift it, but you can just remove it and then push it back <4> sk8ing, yeah, I was thinking of doing something like that <4> sk8ing, I was just asking for suggestions before I try and hack it out :) <4> sk8ing, I dont really want to extend on the list STL or anything, just need to implement something quick :) <6> the thing with the list is that you should be able to move the element to the end very quickly <6> with out removing it <6> but I don't know how <4> oh <4> something to do with pointers? :) <6> I don't think so <6> it's a linked list so you basicaly would have to specify a new position <5> seems like an odd thing to want <8> NEVERMIND I SOLVED IT <5> Riddle_B0x good <8> not like anybody bothered to help though ^_^ <4> sk8ing, hmmm, shouldn't I use a vector instead of a list? <6> no <4> why? <4> vector is designed for random access? <6> yeah but not for random moving of elements <6> if you'll want to move one element to the end you'll have to move all the other elements after it one position - <5> well, all of the elements between it and the end <4> ok <4> and with a list I can just put it where ever? <5> you could, but you said "one end" <5> so what's the _real_ problem?
Return to
#c++ or Go to some related
logs:
#AllNiteCafe was the airfield where Charles Lindbergh landed to end his historic solo trans a #linux #Linuxhelp banned undernet #MissKitten 4chan teens rules #AllNiteCafe site:www.quotesdb.info g0thicangel
#AllNiteCafe #autumn undernet
|
|