"misirion" <misirion@no_spamyahoo.nospammmmit> wrote...[color=blue]
> [..]
> I'd like to read and write on binary files some vectors of strings, and I
> wrote this code:
>
> ifstream fin(conf.c_str(),ios::binary);
> char inc[100];
> fin.read( inc, sizeof(levelfiles) );[/color]
I think this is supposed to be
fin.read(inc, sizeof(inc));
, no?
[color=blue]
> levelfiles = fromCharS(inc);
> fin.close();
>
> .... where fromCharS:
>
> vector<string> fromCharS(char* in) {[/color]
I recommend changing the argument to 'const char* in'.
[color=blue]
> vector<string> o;
> vector<string>* tmp = new vector<string>;
> tmp = (vector<string> *)in;[/color]
This is totally bogus, sorry. Casting a pointer to char to a pointer
to a vector is nonsensical. Besides, you're losing the pointer you
just obtained from the free store, which leads to a memory leak.
What are you trying to do? If you want to read all lines in a file
into a vector of strings, there are known solutions (which you can
find in the archives) and they don't involve casting or using 'get'.
They usually involve 'getline'. Search
http://groups.google.com for
them.
[color=blue]
> for (int i=0;i<(int)tmp->size();i++)
> o.push_back( (*tmp)[i] );
> return o;
> }
>
>
> I'd like to know what you think, if this solution is too dirty and most of
> all why it doesn't work: the push_back generates an access violation...[/color]
The part where you cast a pointer to char to a pointer to a vector of
strings makes /no sense/. That's why it doesn't work. Dirty? I have
no idea what meaning you put into that. Not working, plain and simple.
V