Here's my situation.I'm reading a file that consists of characters including white space.Once I read them I'm counting the occurrences of each character.This means I need to count occurrences of white space as well.If I use ifstream I skip the white spaces and I dunno the filesize so I cant use getline.What do I do?
You need to use the unformatted input functions, such as read.
You can either read 1 character at a time and count, or read a block into a buffer then count the characters in the buffer (more efficient as less I/O). If doing the latter you will need to use gcount to find out how many characters you did read when you reach end of file.
See http://www.cplusplus.com/reference/iostream/ifstream/ for info on the various functions, etc.
I think you can do it with the getline function fine... The getline stops at the end of the line, only if you use the ">>" operator stops at white space.
[EDIT]: Something else I just thought about.
If you don't wont to store all the file in a string (because of ram) then you can use a map ( <char, int> ) and read each letter and store it in there.