Read / Write files

This tutorial will demonstrate how to read in a file and also output the details to another file. The headers
fstream and iostream
basically include details on File-streaming (fstream) and In-Output-Streaming (iostream).

I have attached the code within a zip file with the required input file as well.

The namespace denotes which area are you in, for example : maths:algebra would mean you are doing maths and with the topic of Algebra, within the c/c++ example std::ifstream means that the namespace is std and the function/variable is ifstream.

NOTE: the { } are the begin and end of a code structure, e.g. While begin; do something; end;

#include 
#include
#include

using namespace std;// use the namespace (e.g. instead of putting std::ifstream you just need to put fstream.)

int main(void)
{
char InStr[100];
ifstream InFile("countrys.txt",ios::in);// infile
ofstream OutFile("outcountrys.txt", ios::out);// outfile

while (InFile.getline(InStr,100))// while reading each line within the file
{
printf("%s\n", InStr);// output the read line to the console
OutFile <<

Hello World C C++

You can obtain a few version of a c/c++ compiler from GNU, but if you are using Linux then you should have the compiler already installed.

To display the classic Hello World, save this code below

#include <iostream>
 
int main(void)
{
  std::cout << "Hello world!!";
}

as helloworld.c

Then to compile (if using gcc) into the platform that you are using

#Linux
g++ helloworld.c -o helloworld
#Windows because windows likes .exe
g++ helloworld.c -o helloworld.exe

to run the program, you just need to execute the helloworld file that was created from the above command, if you are using Windows, then you will need to change the line to

The output should be

Hello world!!

Well that is the classic!!