Thread: help with fstream

  1. #1
    Registered User
    Join Date
    Oct 2002

    Question help with fstream

    I am very new to c++ and need some help with fstream.h
    Could someone please tell me how to ask the user for a name and make that the name of a .txt please? I imagine it would be something like this...

    int num;
    ofstream a_file(num, ".txt");


    If someone could help with this, or direct me to a advanced tutorial, it would be most appreciated.

  2. #2
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    #include <fstream>
    #include <iostream>
    #include <string>
    int main(){
    	std::ofstream out;
    	std::string str;
    	std::cout << "Enter the name of the file" << std::endl;
    	std::cin >> str;
    		std::cout << "Could not open" << std::endl;
    		return 1;
    	std::cout << "Success!!! Created " << str << std::endl;
    	out << "This is text";

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems with fstream, one variabile for write and read
    By Smjert in forum C++ Programming
    Replies: 3
    Last Post: 02-03-2009, 10:19 PM
  2. Fstream. I/O
    By kevinawad in forum C++ Programming
    Replies: 2
    Last Post: 07-07-2008, 09:19 AM
  3. ARGH! fstream errors
    By OttoDestruct in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2004, 10:37 PM
  4. Are fstream and ofstream incompatible?
    By johnnyd in forum C++ Programming
    Replies: 5
    Last Post: 03-19-2003, 12:21 PM
  5. Problems with fstreams.
    By mosdef in forum C++ Programming
    Replies: 7
    Last Post: 06-19-2002, 03:36 PM