Input Output?

This is a discussion on Input Output? within the C++ Programming forums, part of the General Programming Boards category; Hi all i was wondering if i could get some help on input output. ofstream a_file ( "3D Graph.txt", ios::app); ...

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    82

    Input Output?

    Hi all i was wondering if i could get some help on input output.


    ofstream a_file ( "3D Graph.txt", ios::app);

    for loop;

    Code:
     case 0:
                        {
                        Grid[++x][y][z] = Output[j];
                        a_file << x << "  " << y << "  " << z << "  " << Output[j] << endl;
                        }    
                        break;
    Above is a snippet of the code i'am using:

    Below is what its output looks like:


    28 28 27 1
    28 27 27 1
    28 27 26 1
    27 27 26 1
    27 26 26 1
    28 26 26 1
    28 26 27 1
    28 25 27 1
    28 25 26 1
    29 25 26 1
    29 25 27 1
    29 25 28 1
    29 26 28 1
    28 26 28 1
    28 27 28 1
    28 27 29 1
    28 28 29 1
    28 28 28 1
    29 28 28 1
    29 27 28 1

    And here is what i would like it to look like

    [29,29,29,28,28,28,28,28,27,27,27,27,28,28,28,28,28 ,28,28,28,29,29,29,29,29]

    [28,29,29,29,28,27,26,26,26,26,25,25,25,25,25,24,24 ,23,23,23,23,23,24,24,25]

    [28,28,27,27,27,27,27,26,26,27,27,26,26,27,28,28,29 ,29,28,27,27,26,26,27,27]

    Anyone know of a snazzy way to do it bar just putting each line in a seperate txt file?

    any help appreciated

    Regards Wolfe

  2. #2
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,262
    What's wrong with each bar on a separate line? You could create a special restricted character, like ';', or something, which is inserted to the end. So when you read it in, and get a ';', you'll know it should go on a new line. or just use the [ and ] things like you did there, and work away.

    regards

    >> ofstream a_file ( "3D Graph.txt", ios::app);

    I normally prefer to use in if it's an ifstream, or out if an ofstream like so:

    ofstream out ( "3D Graph.txt", ios::app);

    it's just a_file isn't exactly a useful description of what the stream is meant to be doing.

  3. #3
    Registered User
    Join Date
    Oct 2005
    Posts
    82
    The original format can't be copy an pasted into matlab like this:

    [29,29,29,28,28,28,28,28,27,27,27,27,28,28,28,28,28 ,28,28,28,29,29,29,29,29]

    Thats why i can't use the original format i have to write it out each time

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Input and Output files
    By matrixhelp in forum C Programming
    Replies: 1
    Last Post: 03-10-2008, 03:07 AM
  2. Replies: 5
    Last Post: 02-25-2008, 06:35 AM
  3. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 04:42 PM
  4. Input / Output help (arrays)
    By fp123 in forum C++ Programming
    Replies: 1
    Last Post: 01-15-2006, 12:30 PM
  5. output as input
    By DDC in forum Linux Programming
    Replies: 3
    Last Post: 02-23-2003, 07:59 AM

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