On Thu, 2026-08-27 at 07:22 +0200, [email protected] wrote:
> On Wed, Aug 26, 2026 at 07:15:00PM +0000, Jean-Christophe wrote:
> > hello,
> > 
> > i try to write an my_files.txt
> > 
> > and see the output on tty
> 
> As Dan Ritter said in this thread: you are calling fonction_deux:
> 
> > bool fonction_deux (){
> >     fstream my_file;
> >     my_file.open("my_file.txt", ios::out);
> >     if (!my_file) {
> >             cout << "File not created!";
> 
>         ...and here, you are writing to stdout (what you call "tt", I
> think)
> 
> >     }
> >     else {
> >             cout << "File created successfully!\n" << endl;
> >             cout << fonction_un() << endl;
> > 
> >     my_file.close();
> >     }
> >     var_fonction_deux = true;
> >     return var_fonction_deux;
> > }
> 
> and in all the other places too ("cout" writes to stdout).
> If you want to write to your fstream my_file, which is
> connected to "my_file.txt") you have to do something like
> 
>   my_file << "some text going to file" << endl;
> 
> (See https://www.w3schools.com/cpp/ref_fstream_fstream.asp for a more
> complete example).

bool fonction_deux (){
        fstream MyFile("my_file.txt");
        if (!MyFile) {
                cout << "File not created!";
        }
        else {
                cout << "File created successfully!\n" << endl;
                 MyFile << fonction_un();

                MyFile.close();
        }
        var_fonction_deux = true;
        return var_fonction_deux;
}

I was inspired by the code, but I have the following compilation error:

$ g++ -std=c++23 test-fonction.cpp test-fonction.out 
/usr/bin/ld: test-fonction.out: _ZSt4cout: invalid version 2 (max 0)
/usr/bin/ld: test-fonction.out: error adding symbols: bad value
collect2: error: ld returned 1 exit status

> Cheers

Cheers

Reply via email to