2 Replies - 236 Views - Last Post: 15 August 2012 - 09:25 AM Rate Topic: -----

#1 persianmess  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 09-July 12

comparing strings

Posted 15 August 2012 - 05:38 AM

#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?

This post has been edited by no2pencil: 15 August 2012 - 06:39 AM
Reason for edit:: Completely corrected this post... horrible


Is This A Good Question/Topic? 0
  • +

Replies To: comparing strings

#2 no2pencil  Icon User is offline

  • Original Digital Gansta
  • member icon

Reputation: 4503
  • View blog
  • Posts: 24,971
  • Joined: 10-May 07

Re: comparing strings

Posted 15 August 2012 - 06:37 AM

If you are going to be a member here, there are some things you need to start doing correctly. These things are simple, & are explained to you when you create a new topic, but you failed to read or follow them.

1.) Don't name your topic "Need help with this program". The purpose of Dream In Code is to answer questions. It's pretty much a given that if you are posting, you probably have a question &/or need help. If you can't give your topic a descriptive name, then please don't bother posting.

2.) Don't post coding questions under the Challenges sub-forums. Just because it's a challenge for you, doesn't mean it's acceptable for the challenge sub-forum. If you don't know what should be posted under the challenges sub-forums, then that's clue enough that you shouldn't be posting there.

3.) Use code tags. Why? Because it will add what little, shoddy indenting that your code offers.
Was This Post Helpful? 1
  • +
  • -

#3 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5723
  • View blog
  • Posts: 22,637
  • Joined: 23-August 08

Re: comparing strings

Posted 15 August 2012 - 09:25 AM

It makes no sense at all because target is never, ever, given a value (other than the default empty string).

EDIT: Also spammed here and here
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1