3 Replies - 1062 Views - Last Post: 27 September 2012 - 03:30 AM Rate Topic: -----

#1 koji52  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 25-September 12

Question: C++ File Handling

Posted 26 September 2012 - 12:32 AM

is it possible to create a new file(example .txt file) using file handling?
so far I know is Read,Write and Append function from File Handling.

if there is, can you give the parameter or syntax?
Is This A Good Question/Topic? 0
  • +

Replies To: Question: C++ File Handling

#2 kai_itz me  Icon User is offline

  • D.I.C Head

Reputation: 28
  • View blog
  • Posts: 159
  • Joined: 03-August 12

Re: Question: C++ File Handling

Posted 26 September 2012 - 01:52 AM

check for this :

http://www.mycplus.c.../file-handling/
Was This Post Helpful? 0
  • +
  • -

#3 raghav.naganathan  Icon User is offline

  • Perfectly Squared ;)
  • member icon

Reputation: 408
  • View blog
  • Posts: 1,440
  • Joined: 14-September 12

Re: Question: C++ File Handling

Posted 26 September 2012 - 02:01 AM

View Postkoji52, on 26 September 2012 - 01:02 PM, said:

is it possible to create a new file(example .txt file) using file handling?
so far I know is Read,Write and Append function from File Handling.

if there is, can you give the parameter or syntax?


well, you can always use open() to create a new file. What this does is if there is no file which exists with the same name,then a new file is created.

eg.
#include<iostream.h>
#include<fstream.h>
int main()
{
ofstream myFirstFile;
  myFirstFile.open ("FirstFile.txt");
  myFirstFile<<"Hello! This is a new file that has been created.\n";
  myFirstFile.close();
  return 0;
}



Your output will be a new file created with name FirstFile.txt having "Hello! This is a new file that has been created."

regards,
Raghav
Was This Post Helpful? 0
  • +
  • -

#4 mmakrzem  Icon User is offline

  • D.I.C Head

Reputation: 5
  • View blog
  • Posts: 56
  • Joined: 11-January 08

Re: Question: C++ File Handling

Posted 27 September 2012 - 03:30 AM

have a look at the doc's for fstream: http://www.cplusplus...stream/fstream/

The second parameter lets you specify how you should open a file stream, input (read), output (write), whether you want to truncate (clear if already file exists) etc.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1