Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 17-02-2009
Member
 
Join Date: Feb 2009
Posts: 10
Function to create a file in C++?

Hello!

I need code for creating a file in C++

Please help!
Reply With Quote
  #2  
Old 17-02-2009
Member
 
Join Date: May 2008
Posts: 72
Re: Function to create a file in C++?

Hello Rupali!

You need to study these concepts!

http://www.codersource.net/cpp_file_io.html
Reply With Quote
  #3  
Old 17-02-2009
Member
 
Join Date: May 2008
Posts: 35
Re: Function to create a file in C++?

Code:
#include <iostream>
#include <fstream>

int main() {
  std::ofstream o("Hello.txt");

  o << "Hello, World\n" << std::endl;

  return 0;
}
Reply With Quote
  #4  
Old 17-02-2009
Member
 
Join Date: May 2008
Posts: 26
Re: Function to create a file in C++?

To create a new file, open an existing file, or save a file, you use the fopen() function. Its syntax is:

FILE *fopen(const char *FileName, const char *Mode);

The first argument, FileName, must be a valid name of a file. If the user is creating or saving a new file, you can let him specify the name of the file, following the rules of the operating system. If the user is opening an existing file, you can make sure the file really exists, retrieve its name and pass it to the fopen() function.

Because the fopen() function is used to save a new file, to open an existing one, or to save a file that was only modified, the second argument, Mode, actually allows you to decide what operation the function will be used to perform.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Function to create a file in C++?"
Thread Thread Starter Forum Replies Last Post
Driver error: Cannot create a file when that file already exists Nickason Windows XP Support 1 21-03-2013 03:52 PM
How to create generic get object function in c++? KADRI Software Development 5 27-03-2012 11:35 PM
Windows 7: Unable to create file with File system error (65535) TheHibiscus Operating Systems 4 23-01-2011 07:07 PM
Create a function for comparing character strings Zool Software Development 3 16-10-2009 01:09 PM
Windows Backup : Cannot create a file when that file already exists Animorc Operating Systems 3 04-06-2009 09:40 AM


All times are GMT +5.5. The time now is 01:41 AM.