Thread: Copy from cout to hard file?

  1. #1
    random number generator reRanger's Avatar
    Join Date
    Oct 2004
    Posts
    44

    Arrow Copy from cout to hard file?

    I am nearing the end of a small program which allows the user to cull the letter frequency of encrypted text and display it in standard output. I thought that I would allow the ability to save a hardcopy of their results in a drive-file. I have figured out how to do this, but not without preventing each character from displaying on the console screen. I would like to retain screen print while at the same time recording data into text file. Any hints or help would be greatly appreciared.

    reRanger
    "Nay! But you love the present life!"

  2. #2
    Hello,

    Since you are dealing with C++, I would recommend ofstream.

    ofstream: File class for writing operations (derived from ostream)

    Here is a nice tutorial on how to open, write, and close the file properly: C++ tutorial: 6.1, Input/Output with files

    Other resources:

    If you have further questions, please feel free to ask.


    - Stack Overflow
    Segmentation Fault: I am an error in which a running program attempts to access memory not allocated to it and core dumps with a segmentation violation error. This is often caused by improper usage of pointers, attempts to access a non-existent or read-only physical memory address, re-use of memory if freed within the same scope, de-referencing a null pointer, or (in C) inadvertently using a non-pointer variable as a pointer.

  3. #3
    random number generator reRanger's Avatar
    Join Date
    Oct 2004
    Posts
    44

    Ty

    Stack:
    thank-you for you informed and timely reply, Stack Overflow (and, I will probably post again this weekend if I cannot make it work correctly).

    reRanger
    "Nay! But you love the present life!"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 12:44 PM
  2. Formatting a text file...
    By dagorsul in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 03:53 AM
  3. Need Help Fixing My C Program. Deals with File I/O
    By Matus in forum C Programming
    Replies: 7
    Last Post: 04-29-2008, 07:51 PM
  4. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  5. Simple File encryption
    By caroundw5h in forum C Programming
    Replies: 2
    Last Post: 10-13-2004, 10:51 PM