CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Threaded View

  1. #1
    Join Date
    Apr 2019
    Posts
    2

    trancate fonction

    Hi,

    I'm using c++ (2011) with the truncate function. I would like to cut the file fichier.txt after the byte 1000.
    So here is my programm

    I would like to use the truncate function.
    Here is the program

    Code:
    using namespace std;
    #include <string>
    #include <fstream>
    #include <stdio.h>
    #include <unistd.h>
    
     // namespace std;
    // {
    // include <string>
    // }
     int main()
     {
    
    ///// creation d'un fichier random avec des a aux bits Ã* supprimer
    /// marche pas
    
    fstream lulu;
    lulu.open("C:/Users/H2O/Desktop/odoo_exe/fichier.txt",ios::out);
    
    for (int i=1;i<900;i=i+1)
    {
    lulu << "bonjour le monde"<<i<<"\n";
    }
    truncate ("C:/Users/H2O/Desktop/odoo_exe/fichier.txt",10000);
    lulu.close();
    
     	return 0;
    }
    And here is the file

    bonjour le monde 1
    ...../ like that
    bonjour le monde478
    bonjour le monde479
    bonjour le monde480
    bonjour le monde481
    // the file should stop here but it starts again
    bonjour
    bonjour le monde890
    bonjour le monde891
    bonjour le monde892
    bonjour le monde893
    bonjour le monde894
    bonjour le monde895
    bonjour le monde896
    bonjour le monde897
    bonjour le monde898
    bonjour le monde899

    So i don't understand what is going on

    thank you
    Last edited by 2kaud; April 29th, 2019 at 03:19 AM. Reason: Added code tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured