I am currently having issues with parsing a string to fill variables. At the moment the string is filled with unnecessary whitespace which I am erasing. After that, my goal is to parse the data into their specific variables
Reservation::Reservation() : resID(), resName(""), email(""), people(""), day(""), hour(""){}
Reservation::Reservation(const std::string& m_res) : stringfile(m_res)
{
while (stringfile.find(" ") != std::string::npos) {
auto pos = stringfile.find("");
stringfile.erase(pos);
}
.
this->resName = stringfile.substr(0,8);
std::cout << resName << std::endl;
}
Above is a snippet of my code. What is currently happening is that it seems everything gets erased. When running a test of the program the output is just whitespace. If I do this instead this->resName = m_res.substr(0,8);, it will return what I want but none of the whitespaces is trimmed.
To do this task I am using substr(). Is there something I am blindly missing? I'm not sure as to why my entire stringfile is blank, even if I just print``std::cout << stringfile << std::endl;`
Here is a snippet of the text file that needs to be parsed to make things easier
# ID : Name , email, # of people, Day, Time
#------------------------------------------------------------
RES-001: John , [email protected] , 2, 3, 5
I am also lost on how to find and parse each section to their own variable. It seems straight forward but I just can't figure it out.
std::istringstream. Also, are those commas part of the input text file?