Thread: Text File

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    1

    Text File

    I was wondering how you make a textin.dat file and change the
    input to my txtOut.dat file? Here is my code below

    // Character.cpp : Defines the entry point for the console application.

    #include "stdafx.h"
    #include <iostream>
    #include <fstream>

    using namespace std;

    int main()
    {
    cout << "Character Generator v1.0 - Programmed In C++
    By: Rob" << "\n";
    char Name[50], Class[50], Race[50];
    cout << "Character Name: ";
    cin>>Name;
    cin.ignore();
    cout << "Character Class: ";
    cin>>Class;
    cin.ignore();
    cout << "Character Race: ";
    cin>>Race;
    cin.ignore();
    cout << "Outputting To File..." << "\n";
    ofstream a_file ( "Character.txt" );
    a_file<<Name;
    a_file<<"\n";
    a_file<<Class;
    a_file<<"\n";
    a_file<<Race;
    a_file.close();
    ifstream b_file ( "txtOut.dat" );
    cout << "Character Outputted To This Program's Directory."
    << "\n";
    cout << "Press Enter To Exit...";
    cin.get();
    return 0;

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    You pretty much do exactly what you did with cin but with b_file instead.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Don't forget the [code][/code] tags.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  2. A bunch of Linker Errors...
    By Junior89 in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2006, 02:59 PM
  3. Simple File encryption
    By caroundw5h in forum C Programming
    Replies: 2
    Last Post: 10-13-2004, 10:51 PM
  4. checking values in a text file
    By darfader in forum C Programming
    Replies: 2
    Last Post: 09-24-2003, 02:13 AM
  5. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 03:58 PM