bintom
unread,Oct 3, 2017, 10:22:28 AM10/3/17You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
I have the following C++ program that uses an fstream object to read each character in a text file "MyStory.txt" and replace the lower-case alphabets with upper case.
It wasn't working initially, so I added a tellp() function call to tell me the position of the write pointer. And lo and behold, the program started working fine. But I have no clue at the rationale of this behaviour. Also, is there a better (more sensible) way of getting the program to do its job?
int main()
{ fstream io("MyStory.txt", ios::in | ios::out | ios::ate);
char ch;
io.seekg(0);
io.seekp(0);
while(io)
{ io.get(ch);
if(!io)
break;
if(islower(ch))
{ ch = toupper(ch);
io.seekp(-1, ios::cur);
io.put(ch);
io.tellp();
}
}
io.close();
}