Why doesnt this work?

I am trying to get the entire contents of a text file, and i am looking at this push back reference and I copied it almost the same, but It still wont work, why?

http://www.cplusplus.com/reference/string/string/push_back/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
int main()
{
    std::cout << "Find and replace\n" << std::endl;

    std::string strToFind, strToSearch, replaceWith;
    std::string::size_type pos;

    std::ifstream openf("text.txt");

    while(!openf.eof() strToFind.push_back(openf.get()));

    std::cout << strToSearch << std::endl; //Debug Line

    FindandReplace(strToFind, strToSearch, replaceWith, pos);

    return 0;
}


EDIT: Errors are

||=== Build: Debug in Find and Replace (compiler: GNU GCC Compiler) ===|
C:\Users\thund_000\Desktop\Find and Replace\main.cpp||In function 'int main()':|
C:\Users\thund_000\Desktop\Find and Replace\main.cpp|17|error: expected ')' before 'strToFind'|
C:\Users\thund_000\Desktop\Find and Replace\main.cpp|17|error: expected ';' before ')' token|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
Last edited on
The compiler says it right there, it expected a ')' before 'strToFind' on the line 17 (which is 10 in your code snippet).
Your while loop's closing parenthesis is after your push_back() line, you're trying to call separate functions/instruction inside the while condition.
1
2
while(!openf.eof() )
    strToFind.push_back(openf.get());
Last edited on
ah ok thank you.
Topic archived. No new replies allowed.