I have the following code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
fstream file;
string s;
//file contains the following
//id="123456789"
//Note: There is no spaces at the end
file.open("test.txt", ios::in);
getline(file, s);
s = s.substr(s.find("\"")+1, s.length()-1);
cout << s << endl;
return 0;
}
The results print:
123456789"
Why is there a quote at the end? A weird thing is that when I change s.length()-1 to s.length()-5, the code work how I wanted it to. What is the problem here?