outputting to a file

This is a discussion on outputting to a file within the C++ Programming forums, part of the General Programming Boards category; Ok i have to output a translation into a file called decodeOut. I am having troubles doing this. Here is ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    30

    outputting to a file

    Ok i have to output a translation into a file called decodeOut. I am having troubles doing this. Here is what I have wrote and it doesnt work. trans is what I want to put into decodeIn.
    ofstream outfs("decodeOut", ios:ut);
    trans= fs.put();

    Am i missing something or do i just have the worng syntax or what. any help is greatly appreciated.
    Thanks a lot, Kyle

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    30
    That is not supposed to be the face there it is supposed to be
    : : o without the spaces in it.

  3. #3
    Unregistered
    Guest
    HI,

    We need some more info, what is trans? is this is an object?

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    30
    trans is a bunch of charechters. What it is doing is decoding a message and calling it trans. Then that has to be put in to the file.
    Thanks for nay help, Kyle

  5. #5
    Registered User
    Join Date
    Aug 2001
    Posts
    154
    Well, is trans a string variable, a file with characters, a char pointer, etc?
    Here's a quick decode example from an encoded file to a decoded file. Decoding is just subtracting one from the character, which had one added when encoded. The decoding and writing to a file is one operation here.
    Code:
    while (fileIn2.get(ch))			// Decrypt data
    		fileOut2.put(ch - 1);
    fs.put may be reading in one character at a time, but you may be trying to give it a string. You may need a loop or different variable type for trans.

  6. #6
    Registered User
    Join Date
    Oct 2001
    Posts
    30
    It is decoding the charechters one at a time. So i want it to enter one charechter at a time into decodeOut. The problem is that the way I have it set up the only charechter that shows up in decodeOut is the last charechter. So for some reason it overwrites the previous charechter. Any Idea on what could cause this?
    Thanks again, Kyle

  7. #7
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Maybe:

    ofstream outfs("decodeOut", ios::out);
    outfs.put(trans);

  8. #8
    Registered User
    Join Date
    Aug 2001
    Posts
    154
    Originally posted by simhap
    It is decoding the charechters one at a time. So i want it to enter one charechter at a time into decodeOut. The problem is that the way I have it set up the only charechter that shows up in decodeOut is the last charechter. So for some reason it overwrites the previous charechter. Any Idea on what could cause this?
    Thanks again, Kyle
    Well, looks like you need to output to a file or array or something. The problem is that trans is overwritten each time. If trans is a file object, use the file syntax. See my example above, or swoopy's.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 11:39 PM
  2. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 05:27 PM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  4. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 11:12 PM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21