reading files
-
I have done a fair chunk of reading and writing from/to files, but I was wondering if there is anyway of not specifying the input buffer's size when you are reading in. For instance, I would like to read in an entire line, but I don't want to read it into a TCHAR x[1000], I want to read it into something more flexible. how would i do this?
-
I have done a fair chunk of reading and writing from/to files, but I was wondering if there is anyway of not specifying the input buffer's size when you are reading in. For instance, I would like to read in an entire line, but I don't want to read it into a TCHAR x[1000], I want to read it into something more flexible. how would i do this?
If you are into
iostream
s, this is the way:std::istream in;
std::string str;
...
std::getline(in,str);Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
-
I have done a fair chunk of reading and writing from/to files, but I was wondering if there is anyway of not specifying the input buffer's size when you are reading in. For instance, I would like to read in an entire line, but I don't want to read it into a TCHAR x[1000], I want to read it into something more flexible. how would i do this?
CFile myFile("theFile.dat", options);
int nSize = 663;
char* buff = new char[nSize];
myFile.Read(&buff, nSize);
delete [] buff;
I think this is what yer after... "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
-
I have done a fair chunk of reading and writing from/to files, but I was wondering if there is anyway of not specifying the input buffer's size when you are reading in. For instance, I would like to read in an entire line, but I don't want to read it into a TCHAR x[1000], I want to read it into something more flexible. how would i do this?
Read into a CString. Nish Nish was here, now Nish has gone; He left his soul, to turn you on; Those who knew Nish, knew him well; Those who didn't, can go to hell. I like to :jig: on the Code Project Sonork ID 100.9786 voidmain www.busterboy.org
-
Read into a CString. Nish Nish was here, now Nish has gone; He left his soul, to turn you on; Those who knew Nish, knew him well; Those who didn't, can go to hell. I like to :jig: on the Code Project Sonork ID 100.9786 voidmain www.busterboy.org
Holy christ nice timing Nish! :) "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
-
Holy christ nice timing Nish! :) "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
This is unfair :) my answer gets listed the last, yet its associated time is prior than the others' !! Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
-
This is unfair :) my answer gets listed the last, yet its associated time is prior than the others' !! Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
Joaquín M López Muñoz wrote: This is unfair my answer gets listed the last, yet its associated time is prior than the others' !! ;P "An expert is someone who has made all the mistakes in his or her field" - Niels Bohr
-
This is unfair :) my answer gets listed the last, yet its associated time is prior than the others' !! Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
Joaquín M López Muñoz wrote: my answer gets listed the last, yet its associated time is prior than the others' !! Thats cause you used STL in your answer. Chris M might not like that much. Nish :-D :-D Nish was here, now Nish has gone; He left his soul, to turn you on; Those who knew Nish, knew him well; Those who didn't, can go to hell. I like to :jig: on the Code Project Sonork ID 100.9786 voidmain www.busterboy.org
-
Joaquín M López Muñoz wrote: my answer gets listed the last, yet its associated time is prior than the others' !! Thats cause you used STL in your answer. Chris M might not like that much. Nish :-D :-D Nish was here, now Nish has gone; He left his soul, to turn you on; Those who knew Nish, knew him well; Those who didn't, can go to hell. I like to :jig: on the Code Project Sonork ID 100.9786 voidmain www.busterboy.org
LOL :laugh: Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
-
If you are into
iostream
s, this is the way:std::istream in;
std::string str;
...
std::getline(in,str);Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
That's definitely the way I'd do it (you need an ifstream though not an istream) you get all the flexibility in the world and code re-use goes up 'cos you're not having to talk MFC. You can always use .c_str() on it if you need to get down and dirty. Why does anybody use anything else? I hear The Prisoner and 7of9 aren't getting along too well these days.