Click here to Skip to main content
16,007,885 members
Home / Discussions / ATL / WTL / STL
   

ATL / WTL / STL

 
JokeRe: when to/why use Allocator::construct()? Pin
led mike14-Nov-07 4:46
led mike14-Nov-07 4:46 
QuestionPush File into STL list Pin
Jeffrey Walton9-Nov-07 9:36
Jeffrey Walton9-Nov-07 9:36 
AnswerRe: Push File into STL list [modified] Pin
Rajasekharan Vengalil10-Nov-07 12:51
Rajasekharan Vengalil10-Nov-07 12:51 
GeneralRe: Push File into STL list Pin
Jeffrey Walton10-Nov-07 13:21
Jeffrey Walton10-Nov-07 13:21 
AnswerRe: Push File into STL list Pin
Stephen Hewitt11-Nov-07 15:49
Stephen Hewitt11-Nov-07 15:49 
GeneralRe: Push File into STL list Pin
Jeffrey Walton12-Nov-07 5:09
Jeffrey Walton12-Nov-07 5:09 
GeneralRe: Push File into STL list Pin
Stuart Dootson12-Nov-07 15:11
professionalStuart Dootson12-Nov-07 15:11 
AnswerRe: Push File into STL list Pin
Stuart Dootson11-Nov-07 22:54
professionalStuart Dootson11-Nov-07 22:54 
Eeep - I wouldn't use a list for that - as the others have said, use a vector.

Once you get past that, the easiest way to populate the vector is like this (or a list, actually, as shown):
<code>std::ifstream file (filename);
std::vector<char> vectorStore(std::istream_iterator<char>(file), std::istream_iterator<char>());
{or}
</code><code>std::list<char> listStore(std::istream_iterator<char>(file), std::istream_iterator<char>());</code>
This may discard line-endings in text (as opposed to binary) mode - I'm not sure.

An alternative (and more efficient for big files) approach would be to reserve enough space in the vector before reading the file:
      std::vector<char> fileContents;
      struct _stat stat;
      if (_stat(filename, &stat) == -1) throw std::runtime_error("Can\'t open " + file);
      fileContents.resize(stat.st_size);
      std::ifstream file(filename);
      std::copy(std::istream_iterator<char>(file), std::istream_iterator<char>(),
                fileContents.begin());
Once you have the contents in a vector, parse them from there. Use iterators to keep track of input location.



GeneralRe: Push File into STL list Pin
Jeffrey Walton12-Nov-07 5:11
Jeffrey Walton12-Nov-07 5:11 
GeneralRe: Push File into STL list Pin
Stuart Dootson12-Nov-07 15:07
professionalStuart Dootson12-Nov-07 15:07 
GeneralRe: Push File into STL list Pin
Jeffrey Walton12-Nov-07 15:37
Jeffrey Walton12-Nov-07 15:37 
AnswerRe: Push File into STL list Pin
Jeffrey Walton12-Nov-07 5:24
Jeffrey Walton12-Nov-07 5:24 
QuestionGive me a sample of a function returning bitset (STL) Pin
Ontanggabe Parulian7-Nov-07 19:53
Ontanggabe Parulian7-Nov-07 19:53 
AnswerRe: Give me a sample of a function returning bitset (STL) Pin
Stuart Dootson7-Nov-07 21:33
professionalStuart Dootson7-Nov-07 21:33 
Answer:) Re: Give me a sample of a function returning bitset (STL) [SOLVED and thanks] Pin
Ontanggabe Parulian7-Nov-07 22:36
Ontanggabe Parulian7-Nov-07 22:36 
GeneralRe: Give me a sample of a function returning bitset (STL) Pin
Rob Caldecott7-Nov-07 23:14
Rob Caldecott7-Nov-07 23:14 
GeneralRe: Give me a sample of a function returning bitset (STL) Pin
Stuart Dootson8-Nov-07 7:04
professionalStuart Dootson8-Nov-07 7:04 
GeneralRe: :) Re: Give me a sample of a function returning bitset (STL) [SOLVED and thanks] Pin
ThatsAlok24-Nov-07 0:18
ThatsAlok24-Nov-07 0:18 
QuestionATL &amp; WTL CString problem Pin
Fernando A. Gomez F.7-Nov-07 11:45
Fernando A. Gomez F.7-Nov-07 11:45 
AnswerRe: ATL &amp; WTL CString problem Pin
George L. Jackson7-Nov-07 14:13
George L. Jackson7-Nov-07 14:13 
GeneralRe: ATL &amp; WTL CString problem Pin
Fernando A. Gomez F.7-Nov-07 14:17
Fernando A. Gomez F.7-Nov-07 14:17 
GeneralRe: ATL &amp; WTL CString problem Pin
George L. Jackson7-Nov-07 14:54
George L. Jackson7-Nov-07 14:54 
GeneralRe: ATL &amp; WTL CString problem Pin
Fernando A. Gomez F.7-Nov-07 15:02
Fernando A. Gomez F.7-Nov-07 15:02 
GeneralRe: ATL &amp; WTL CString problem Pin
George L. Jackson7-Nov-07 15:06
George L. Jackson7-Nov-07 15:06 
AnswerRe: ATL &amp;amp;amp;amp; WTL CString problem [modified] Pin
George L. Jackson7-Nov-07 15:21
George L. Jackson7-Nov-07 15:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.