Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C++
Memory errors HELP!
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="int2str, post: 2544028"] [snipped code] Hard to tell for sure, but it looks like a memory error. You're trying to allocate 20000 strings of 30 character length on the stack. That's stretching it for sure. The code you posted mixes a lot of "C style" with C++ functions and classes. Why not go all the way and make your code look a little more friendly? Like so: #include <iostream> #include <string> #include <fstream> #include <sstream> #include <vector> using namespace std; struct Doc { string name; string edition; }; int main() { ifstream ff( "test.dat" ); string line; vector<Doc> documents; documents.reserve( 10000 ); while( getline( ff, line )) { string::size_type comma_pos = line.find( ',' ); if ( string::npos == comma_pos ) continue; Doc doc; doc.name = line.substr( 0, comma_pos ); doc.edition = line.substr( comma_pos + 1 ); cout << doc.name << " " << doc.edition << endl; documents.push_back( doc ); } } You can then process the documents vector in any way you like. Cheers, Andre [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C++
Memory errors HELP!
Top