Re: basic function call an function under fstream

Jean-Christophe <[email protected]>
Newsgroups gmane.linux.debian.user
Message-ID <963de5d869b261db24de66d9494e0510f4cc9cd2.camel@blues-softwares.net>
Hi bro,

no that is compile, but file note created.

i don't understand why.

take care,
have best.

jean-christophe
--

#include <iostream>
#include <fstream>
using namespace std;

bool var_fonction_un = false;
bool var_fonction_deux = false;

int age=25;
int bd=100;


char * fonction_un() {
        cout << "chocolat" << endl;;
        cout << "chocolat " << age << "ans" << endl;
        cout << "chocolat a environ " << bd << " bandes-dessinées." <<
endl;
 
	//var_fonction_un = true;
        return file;
}

char * fonction_deux (){
  fstream my_file;
  my_file.open("my_file.txt", ios::out);
  if (!MyFile) {
    cout << "File not created!";
  }
  else {
    cout << "File created successfully!\n" << endl;
     MyFile << fonction_un() << endl;

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

int main() {
  fonction_deux(); 

  return 0 ;
}
 



On Thu, 2026-08-27 at 16:39 +0200, [email protected] wrote:
> On Thu, Aug 27, 2026 at 01:55:50PM +0000, Jean-Christophe wrote:
> > On Thu, 2026-08-27 at 15:27 +0200, [email protected] wrote:
> > > On Thu, Aug 27, 2026 at 12:35:46PM +0000, Jean-Christophe wrote:
> > > > On Thu, 2026-08-27 at 14:29 +0200, [email protected] wrote:
> > > > > On Thu, Aug 27, 2026 at 12:24:13PM +0000, Jean-Christophe
> > > > > wrote:
> > > > > > On Thu, 2026-08-27 at 14:21 +0200, [email protected] wrote:
> > > > > 
> > > > > [...]
> > > > > 
> > > > > > > One more thing: what do you expect this line to do?
> > > > > > > 
> > > > > > > >  		 MyFile << fonction_un();
> > > > > > 
> > > > > > just write 1 to the file
> > 
> > i try, but with char * , no file created
> > 
> > see abouve...
> > 
> > $ g++ -std=c++23 test-fonction.cpp -o test-fonction.out 
> > $ ./test-fonction.out 
> > Fils
> > test-fonction.cpp  test-fonction.out
> > $ 
> 
> Wait. This thing below is your program?
> 
> Re-read my previous mails: you forgot something...
> 
> > 
> > #include <iostream>
> > #include <fstream>
> > using namespace std;
> > 
> > bool var_fonction_un = false;
> > bool var_fonction_deux = false;
> > 
> > int age=25;
> > int bd=100;
> > 
> > 
> > char * fonction_un() {
> >         cout << "chocolat" << endl;;
> >         cout << "chocolat " << age << "ans" << endl;
> >         cout << "chocolat a environ " << bd << " bandes-dessinées."
> > <<
> > endl;
> >  
> > 	//var_fonction_un = true;
> >         return 0;
>  ...exactly here ^^^
> 
> > }
> > 
> > bool fonction_deux (){
> >   fstream MyFile("my_file.txt");
> >   if (!MyFile) {
> >     cout << "File not created!";
> >   }
> >   else {
> >     cout << "File created successfully!\n" << endl;
> >      MyFile << fonction_un() << endl;
> > 
> >     MyFile.close();
> >   }
> >   var_fonction_deux = true;
> >   return var_fonction_deux;
> > }
> > 
> > int main() {
> >   fonction_deux(); 
> > 
> >   return 0 ;
> > }
> 
> Again: what does function_un return in your program?
> 
> What should it return?
> 
> Cheers
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.