Results 1 to 4 of 4

Thread: Function to create a file in C++?

  1. #1
    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!

  2. #2
    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

  3. #3
    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;
    }

  4. #4
    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.

Similar Threads

  1. Replies: 1
    Last Post: 21-03-2013, 03:52 PM
  2. How to create generic get object function in c++?
    By KADRI in forum Software Development
    Replies: 5
    Last Post: 27-03-2012, 11:35 PM
  3. Windows 7: Unable to create file with File system error (65535)
    By TheHibiscus in forum Operating Systems
    Replies: 4
    Last Post: 23-01-2011, 07:07 PM
  4. Create a function for comparing character strings
    By Zool in forum Software Development
    Replies: 3
    Last Post: 16-10-2009, 01:09 PM
  5. Replies: 3
    Last Post: 04-06-2009, 09:40 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,488,851.37309 seconds with 16 queries