how to make cout like fprintf???

Nov 2, 2011 at 3:14pm
hello.. i really need help for my assignment.
here it is the problem :

usually we use fprintf to print a string in a file.
which just like this :

fprintf(file,"%s",comment);

but i dont know why it's null in the output.
this is what i have :

string array[100];
array[3]="xx";
fprintf(ffile,"%s",array[3]);

it's result is null,
even when i used

printf("%s",array[3];

it's still null in board.
but if i use

cout<<array[3]<<endl;

it's worked.
now my question is how can i printed it in a file ????
so it can act like fprintf function???? .
thx.
Last edited on Nov 2, 2011 at 3:19pm
Nov 2, 2011 at 3:25pm
You could use a file stream:

1
2
3
4
ofstream myfile("whatever.txt");

string foo = "xx";
myfile << foo;
Nov 2, 2011 at 3:28pm
Or try do smth like this:
printf("%s", array[3].c_str());
Nov 3, 2011 at 12:17am
Oh my God !!! It's work !!! i tried ofstream already, but i forgot to write #include<fstream> hwhwhwhwhw. Btw thx so much both of u !!! now i can continue my works !!!! God bless both of u!!!!! ^^
Nov 3, 2011 at 12:18am
wtf...
What is hwhwhwhwhwhw?
Nov 3, 2011 at 2:28am
that's how i laughed hwhwhwhwhwhwhw
Topic archived. No new replies allowed.