Can someone please find the error in this. | Sololearn: Learn to code for FREE!


Can someone please find the error in this. I have a txt file named file in my desktop but the output is not able to find the number of this and these. I have to submit this code tomorrow, please help me.

11/20/2019 2:09:00 PM


2 Answers

New Answer


This appears to be written for an old compiler, so I could not test it in perfect detail, but what I was able to spot: 1. The file name should be given as a string, i.e. ifstream fin( "file.txt" ); 2. You used cout without including iostream. 3. Both c and d are unused variables. 4. In the second if-statement, you use the assignment operator instead of the comparison operator. 5. Strings like "this" and "these" should be enclosed in double quotation marks, not single quotation marks. 6. You try to compare ch with "this" and "these", but this is actually pointer comparison, not string comparison -> undefined behaviour. Either use for exact comparison or if e.g. "xxxthisxxx" also counts as a valid appearance, or use modern C++ strings in the first place. As an example, here is a program showing how it could be done, not sure of how much use it is to you:


Shadow Thank you so much for taking out your time to tell me where I went wrong ( ^ω^)