I have a text file I need to parse sentences from using a list of predefined delimiters.
One of the delimiters is ."
and another is ?"
to account for sentences ending in quotes.
When I get the value from the .txt file and store it in a string and print it out, it prints fine.
So,
inputFile >> s;
cout << s;
Would yield, say word."
But then when I use this code:
cout << s.substr(s.length()-2);
It prints, literally \235
to the console.
My delimiter algorithm relies on the value of this substring to be ".\""
Why is this happening? What even is this? This is causing my delimiter to not work, since "\235" != ".\""
Main function:
#include <fstream>
#include <string>
#include "iostream"
using namespace std;
int main(int argc, const char * argv[]) {
string s;
ifstream inputFile;
inputFile.open("PATH_TO_FILE/test.txt");
while (!inputFile.eof()) {
inputFile >> s;
cout << "String: " << s << endl;
cout << "Sub: " << s.substr(s.length() - 2) << endl;
}
return 0;
}
test.txt:
“Of course.”
Output:
String: “Of
Sub: Of
String: course.”
Sub: \200\235
Program ended with exit code: 0