Need some help with a program ..

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

using namespace std;

int main ()
{
ifstream inputFile;
inputFile.open ("proud_mary.txt");
ofstream outputFile;
outputFile.open ("ordered_mary.txt");
int counter=0;
int count=0;
int andC=0;
string word;
string target;
const int num=10;

if(!inputFile)
cout<<"file not found"<<endl;
else
{
while (inputFile >> word)
{
if (word=="and")
{
andC++;
word="XXX";
}
if (word >= target)
{
counter++;
cout<<word<<" ";
outputFile<< word<<" ";
}
if (counter % num== 0)
{
cout <<endl;
outputFile <<endl;
count++;
}
}
if (counter % num!=1);
{
count++;
}
}

cout<<endl;
inputFile.close();
cout <<endl;
cout << "Total number of words: "<< counter <<endl;
outputFile << "The number of words: "<< counter <<endl;
cout << "Total number of lines: " << count << endl;
outputFile << "Total number of lines: " << count << endl;
outputFile.close();


return 0;
}




So I did this program above .. and it reads something from a file onto the command prompt ..

My question is, what does "if (word >= target)" this function do? I need to be able to identify it's job in the program. Could anyone please verify?
I did this program above

It is very bad in C++ to write a program without knowing what it does.

word >= target

This compares two string objects and returns true if the string word is considered to be greater (or equal to) the string target. word will be considered greater if the first character in the two that does not match has a greater value in word.

You should experiment with different values of word and target to see for yourself.

You can learn about this here: http://www.cplusplus.com/reference/string/operators/
and here:
http://www.cplusplus.com/reference/string/string/compare/
Topic archived. No new replies allowed.