0

Hello fellow programmers, I have a question that hopefully can be answered by one of you. The following code states that after the txt.file is put into a string variable, the entire string (array of characters) will then be removed of any punctuation and set to lower case alphabet. Both function statements worked fine, however, quotation marks and dashes (' " ', ' - ') were not removed from the string. The second statement in the while loop, which I commented out, was a test to try and remove the quotation from the string but that did not work either. When I 'cout' the string, I am outputting it into another text file. I don't know if the information provided is helpful but any advice would be fantastic thanks!

   `while (fin >> str)
    {
    str.erase(remove_if(str.begin(), str.end(), ::ispunct), str.end()); 
    //str.erase(remove(str.begin(),str.end(),'\"'),str.end());
    transform(str.begin(), str.end(), str.begin(), ::tolower);

    fout << str << " ";}` 
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • Why does line1 have __remove_if__ but line2 have __remove__ ? – Arif Burhan Mar 24 '16 at 03:56
  • Also ispunct is missing **(** – Arif Burhan Mar 24 '16 at 03:57
  • @ArifBurhan You don't put parentheses after a function name if you're passing it as an argument, only when you're calling the function immediately. – Barmar Mar 24 '16 at 04:12
  • Your code works fine for me: http://ideone.com/BJd42i I used `cin` and `cout` instead of files, but that shouldn't matter. – Barmar Mar 24 '16 at 04:22
  • I guess ispunct implemented differently for your platform (it allows - and ") – cha Mar 24 '16 at 05:35
  • Are you (somewhere) setting a non-default locale? `In the "C" locale, ispunct returns true for every printing character for which neither isspace nor isalnum is true.` – Jerry Coffin Mar 24 '16 at 05:47

0 Answers0