Really need help with this .. please help!

#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;
}





Question to you all is, Comparing the two above strings, word and target .. Why would those two strings be compared? If you can tell me this in a way that makes any sense at all .. It's from opening a file with a whole bunch of words .. counting the words .. and the lines .. What would the function if (word >= target) do?
word >= target means that word comes after target in dictionary order (or is the same word as target, as is larger than or equal to).
Last edited on
first its wrong thing to do given that target has no value and for comparision you require that to be initialised.

and veltas I think word >= target first compares length of string then check for dictionary order. for = they must be identicle strings.But I am not sure.
Akshit I looked it up on this website, it says dictionary order, or rather; compares the first non-equal characters matching them up in order.
maybe then
This would also allow you to check if the strings in fact matched.

It's kind of lexicographic, if the capitalisations for each position match and they're all letters. But a > Z according to this system so I suppose it's not quite lexicographical (unless you make sure all letters are the same case in the comparison).
Topic archived. No new replies allowed.