reading from a file, how

This is a discussion on reading from a file, how within the C++ Programming forums, part of the General Programming Boards category; Ok. here is the deal. I am gonna make a program to automatically assemble an html file for me. Is ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    18

    reading from a file, how

    Ok. here is the deal. I am gonna make a program to automatically assemble an html file for me.

    Is gonna make the header. Input the news from a text file, then fill in the rest of the page. Basically a quick and cheap way to get easy updates. Well, here is my problem. It works fine, but looks crappy.

    i am using strings to read in from file to file. However, it does not read in whitespace and escape characters. I guess instead of strings i could use character arrays... any idea?

    thanks

    cow
    cow

  2. #2
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    What function are you using to read the data from the file?

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    18
    my function looks a little something like this. very basic, but gets it done. i have a seperate function right now for each part that is going to be read and written.

    int writehead()
    {
    ifstream infile("header.htmlv4");
    ofstream outfile("page.html");
    string in;
    while(!infile.eof())
    {
    infile >> in;
    outfile << in;
    outfile << " ";
    }
    infile.close();
    outfile.close();
    return 1;
    }
    cow

  4. #4
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    Have you tried using char array?
    I can't be of much help 'cos i never use ifstream/ofstream.

  5. #5
    Registered User
    Join Date
    Feb 2002
    Posts
    18
    i can try but haven't used them in a long, long time. how long of an array should i read in at a time since the lines are of unknown length.

    cow
    cow

  6. #6
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    its not the medium but the input functions your using,

    try

    getline( char* pch, int nCount, char delim = '\n' );

    Code:
    char line[1024];
    
    while(!infile.eof())
    {
        infile.getline(line,1024,'\n');
        outfile.write(line,strlen(line));
        outfile << " ";
    }
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-21-2008, 11:19 PM
  2. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  3. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  4. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 09:46 AM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM

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