Taking input for fstream::seekp and fstream::put
Tag : cpp , By : user133834
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , There are a couple of problems with your code: ostream::seekp sets the "put" pointer, i.e. the location at which one writes data, not the position at which one reads data. Use istream::seekg to set the "get" pointer ostream::tellp doesn't perform any I/O. It merely reports the value of the 'put' pointer, it doesn't actually fetch the data stored there. You mean to use istream::get. fstream mystream;
mystream.seekg(0x16);
int myvar;
myvar=mystream.get();
cout<<"Value at offset 0x16: "<<myvar << "\n";
|
seekp and seekg with fstream
Date : March 29 2020, 07:55 AM
should help you out basic_fstream is derived from basic_iostream which is derived from basic_istream and basic_ostream. So, basic_fstream has function seekp from basic_ostream and function seekg from basic_ifstream. In short, in your case, calls to seekp and seekg do same actions, since actions perfomed by basic_filebuf::seekpos depends only on open mode for basic_filebuf. basic_ostream<charT,traits>& seekp(pos_type pos);
pos_type seekpos(pos_type sp,
ios_base::openmode which = ios_base::in | ios_base::out);
basic_istream<charT,traits>& seekg(pos_type pos);
|
fstream seekg(), seekp(), and write()
Date : March 29 2020, 07:55 AM
wish help you to fix your issue The class template std::basic_filebuf holds a single file position
|
fstream -> seekp()/tellp() won't work
Tag : cpp , By : Ernie Thomason
Date : March 29 2020, 07:55 AM
it fixes the issue To seek to the end of the file, set the relative position to 0 and the base position to ios::end: if (...)
{
std::streampos pos;
file.seekp(0, ios::end); /*
^^^^^^^^^^^^^ */
pos = file.tellp();
std::cout << pos << std::endl;
}
|
c++ fstream write doesn't work with binary file without seekg and seekp
Date : March 29 2020, 07:55 AM
I hope this helps you . i was compiling in visual studio 2010 , and when i took the same code and compiled it on other ides like code blocks , it works fine and outputs the expected results i think it is a .Net issue or something !
|