Go back to Richel Bilderbeek's homepage.

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

 

 

 

 

 

(C++) CfileExample1

 

Technical facts

 

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

 

 

 

 

 

Qt project file: ./CppCfileExample1/CppCfileExample1.pro

 

include(../../ConsoleApplication.pri) #Or use the code below
# QT += core
# QT += gui
# greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
# CONFIG   += console
# CONFIG   -= app_bundle
# TEMPLATE = app
# CONFIG(release, debug|release) {
#   DEFINES += NDEBUG NTRACE_BILDERBIKKEL
# }
# QMAKE_CXXFLAGS += -std=c++11 -Wall -Wextra -Weffc++
# unix {
#   QMAKE_CXXFLAGS += -Werror
# }

SOURCES += main.cpp

 

 

 

 

 

./CppCfileExample1/main.cpp

 

#include <cassert>
#include <cstdio>
#include <memory>

//THIS PROGRAM MIGHT CAUSE A RUNTIME CRASH
//IT PROBABLY CORRUPTS SOME MEMORY
//DO NOT RUN IT!
//
//Sadly, I cannot remember why this was so...
int main()
{
  //Create a file to write to
  const std::unique_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

This page has been created by the tool CodeToHtml