Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) std::fputs

 

std::fputs is a function used in C-style file I/O:

 

Prefer using the C++ file stream std::fstream.

 

#include <cassert>
#include <cstdio>
#include <boost/scoped_ptr.hpp>

//THIS PROGRAM CAUSES A RUNTIME CRASH
//IT PROBABLY CORRUPTS SOME MEMORY
//DO NOT RUN IT!
int main()
{
  //Create a file to write to
  const boost::scoped_ptr<FILE> my_file(std::fopen("my_file.txt","w"));
  //Assume the file is created successfully
  assert(my_file);
  //Put text at the start of the file
  std::fputs("Bilderbickel",my_file.get());
  //Go to the 9th position
  std::fseek(my_file.get(),9,SEEK_SET );
  //Put text at the 9th position
  std::fputs ("k",my_file.get());
  //Close the file
  std::fclose (my_file.get());
}

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict