C - C++ Files - File write

#include <iostream> 
#include <fstream> 
using namespace std; 
 
int main() 
{ 
  ofstream out("test.txt"); 
  if(!out) 
  { 
    cout << "Cannot open file.\n"; 
    return 1; 
  } 
 
  out << 10 << " " << 123.23 << "\n"; 
  out << "This is a text."; 
 
  out.close(); 
 
  return 0; 
}