Code:
while (!my_file.eof())
{
getline (my_file,line);
...
}
This method of controlling loops by testing eof is error prone and rarely done correctly. It is recommended to test the read operation directly, getline in this case:
Code:
while ( getline(my_file,line) )
{
...
}
Code:
string getname()
{
return name;
}
void manipulation()
{
...
}
Member functions that do not modify the class should be const:
Code:
string getname() const
{
return name;
}
void manipulation() const
{
...
}
Code:
int found;
...
found=line.find(word);
if (found != string::npos)
The find member function returns a value of type size_type:
Code:
string::size_type found;
...
found=line.find(word);
if (found != string::npos)
Code:
#include <stdio.h>
#include <stdlib.h>
...
#include <time.h>
Prefer the newer versions of these header files where available:
Code:
#include <cstdio>
#include <cstdlib>
...
#include <ctime>
Code:
fstream my_file;
...
string ext=".txt";
...
my_file.open (getname()+ext);
The fstream object's open member function does not accept string arguments (currently). You need to use the c_str member function to convert the string container into something it does accept. (Has this changed yet?)
Code:
my_file.open ((getname()+ext).c_str());