using string to read file - XCode

Posted by Fernando on Stack Overflow See other posts from Stack Overflow or by Fernando
Published on 2010-04-24T18:31:51Z Indexed on 2010/04/24 18:33 UTC
Read the original article Hit count: 253

Filed under:
|
|

The following does not work and gives me a SIGABRT when I run in the debugger:


std::ifstream inFile;

inFile.open("/Users/fernandonewyork/inputText.txt");    

cout << inFile << endl;

vector<string> inText;

if (inFile) {
    string s4;

    while (inFile>>s4) {
        inText.push_back(s4);
    }

}

inFile.close();

The following does:


std::ifstream inFile;

inFile.open("/Users/fernandonewyork/inputText.txt");    

cout << inFile << endl;

vector<string> inText;

if (inFile) {
    string s4("This is no lnger an empty string");

    while (inFile>>s4) {
        inText.push_back(s4);
    }

}
inFile.close();

I was under the impression I was able to simply use s4 without having to worry about any space considerations, or is something else happening here? This is the full error I get from the top code:

malloc: * error for object 0x100010a20: pointer being freed was not allocated * set a breakpoint in malloc_error_break to debug Program received signal: “SIGABRT”.

© Stack Overflow or respective owner

Related posts about c++

Related posts about mac