how to write into the file at the same time display at screen?if there a command that do it?

I think there there is a *nix shell conmmand that will do it (tee ??) but not in MS-Windows. you might put the output lines into a function then call it twice

void foo(ofstream& out)
   out << "Hello World " << endl;

int main()
   ofstream out("file.txt");

>if there a command that do it?
No, the framework doesn't exist for this, so you would need to add it on your own. You *can* do it with standard streams such that a single write statement copies to a file or vector of files that you choose, but that's an extremely advanced IOStreams technique that involves extending your own tee'd stream, and it's much easier to just explicitly do two writes like Ancient Dragon showed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.