I'll try to clarify thi as best as I can although I'm still beginer when it comes to deal with these issues.
this only prints % .....what am i doing wrong?
Code:
fin.seekg(ios::end);
In ios.h header I found this:
Code:
...
class _CRTIMP ios {
public:
enum io_state { goodbit = 0x00,
eofbit = 0x01,
failbit = 0x02,
badbit = 0x04 };
enum open_mode { in = 0x01,
out = 0x02,
ate = 0x04,
app = 0x08,
trunc = 0x10,
nocreate = 0x20,
noreplace = 0x40,
binary = 0x80 };
enum seek_dir { beg=0, cur=1, end=2 };
...
As you can see ios::end or ios_base::end is nothing else then number 2.
Code:
fin.getline(line, length);
For example, suppose you want to use getline() to read a name into the 20-element name array. You would use this call:
cin.getline(name,20);
This reads the entire line into the name array, provided that the line consists of 19 or fewer characters.
So in your case you have read only one character and that was %.
Now, consider this code:
Code:
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ofstream out("test.txt",ios_base::out);
out<<"%2004-10%\n";
out.close();
ifstream in("test.txt",ios_base::in);
in.seekg(0,ios_base::end);
int len=in.tellg();
cout<<len;
return 0;//you can ommit this according to the ISO C++ standard
}
You'll get 11 as output value.
Because you're using text files unlike binary files where for example an int is always stored as two bytes whereas it's text version "12345" might be five bytes, you get 11 as output value which means that 11 BYTES are stored within file.
Nine bytes from %2004-10% and two bytes from \n because every character occupies one byte of memory.
I hope that will help you!
Please note that I wrote this with best intentions so if some fact is not true I apologize in advance.