fprintf with string argumant

Jan 7, 2010 at 8:19am
Dear all,
In order to creation a formatted file, I want to utilize `fprintf`. it must get `char*` but I have several string variables. I have something like this:
...
string St1, St2;
...
ifstream In("Text.txt");
In >> St1 >> St2;
...
that St1 and St2 are initialized by reading from a file by ifstream() function. Now I want to write them in another file by fprintf() function.
fprintf("%s %s", St1, St2);
But I think fprint get char* not string. Can anyone help me, please?
Thanks
Jan 7, 2010 at 8:22am
The c_str function:

1
2
3
string foo = "foobar";

fprintf( myfile, "%s", foo.c_str() );
Jan 7, 2010 at 8:29am
Thanks alot. It works.
Regards
Topic archived. No new replies allowed.