1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

about to insert a line into a text file

Discussion in 'C++' started by michal, Sep 22, 2014.

  1. michal

    michal New Member

    Joined:
    Sep 12, 2014
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    Hello to every one again
    I'm making a project that it generates some kind of report in html format, to do this i was using file streams, and all goes fine until i need to insert data between last data posted and the end of page, i means before the </body> and </html> tags. I was reading around some pages and it sayed that it is impossible, that's true??

    or i have a better idea: to remove the end tags and append the new data with the end tags every time. but how i can to go to that position of end tags??

    thanks, gracias
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,309
    Likes Received:
    369
    Trophy Points:
    83
    Why not just replace </body></html> with the report data and then append </body></html> to the content. Just do that before the final output flush.
     
  3. michal

    michal New Member

    Joined:
    Sep 12, 2014
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    Ok, that's the idea that i have but, how i can to pointer to two lines before the EOF, sorry but i don't know much about file streams theory, can you to tell me about any streams free tutorial?
    I need that it be free because i'm living in cuba.

    Thanks for all, "gracias por todo"
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,309
    Likes Received:
    369
    Trophy Points:
    83
    Read all data into a variable, then find the position of the content and then add more content in that string and then write back all the data.

    Other option is to use the string position to place the cursor where you found the content and then append to the file.
     
  5. michal

    michal New Member

    Joined:
    Sep 12, 2014
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    thanks for the idea, i hope that the endl at the end of each line don't be a problem while i try to store all the file data in a string variable.

    thanks again
     
  6. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,309
    Likes Received:
    369
    Trophy Points:
    83
    Should not be.
     
  7. michal

    michal New Member

    Joined:
    Sep 12, 2014
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    how many characters can to store a string variable?, my report, each time, is about the flash memory content but in text format. i'm talking about, may be, a one or two MBytes in a txt document, but store in one string variable, it's possible to do that??

    Thanks shabbir
     
  8. michal

    michal New Member

    Joined:
    Sep 12, 2014
    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    how many characters can to store a string variable?, my report, each time, is about the flash memory content but in text format. i'm talking about, may be, a one or two MBytes in a txt document, but store in one string variable, it's possible to do that??

    Thanks shabbir
     
  9. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,309
    Likes Received:
    369
    Trophy Points:
    83
    Yes it should not be an issue and are you allocating the memory using pointer or you are using it as variable.

    If using as variable try using a pointer and try to allocate that amount of memory and see if it works.
     

Share This Page