0

How can i manage to open a file and read some fixed (lets assume n) lines of ASCII code, and after that switch to reading BINARY from the same file starting with the n+1 line in C++?

2
  • If you've opened the file with fopen in text mode, you can re-open it in binary mode with freopen. If that's what you mean. Commented Aug 12, 2014 at 5:07
  • and will it keep reading from n+1 line, not reopen the file? I was looking for a c++ solution via fstream, but i guess that's fine too. Commented Aug 12, 2014 at 5:12

1 Answer 1

1

You can't change the mode without reopening because the fstream uses system calls to open files which in turn do not allow a mode change. You can use tellg / seekg to save and later restore the reading position, respectively.

Sign up to request clarification or add additional context in comments.

1 Comment

I guess I'll mark your answer as accepted since I was thinking the same, but I waited for another possibility. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.