You are on page 1of 1

File in simple way

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

void main()
{
ifstream input;
input.open("PetList.txt");
if (input.fail()) //true
cerr<<" Cant find the file\n";

int counter=0;
string name;
while(!input.eof())
{
input>>name;//retrive info frm file
cout<<name<<endl;//output black screen
if (name=="Galaxy")
counter++;
}
cout<<"number of pets which are similar :\n"<<counter;

ofstream output;
output.open("test.txt");
output<<"the first line in file \n"<<"Happy Me :)"<<endl;
output.close();

input.close();

getchar();
}

You might also like