5
hidden
5y

Stack overflow is full of useless assholes, like I asked a specific question about a problem I am having that is similar to another problem that exists but it is not the same at all in terms of how to fix and instead of helping I’ve got 2 downvotes on it and a comment linking me to a completely unrelated stylistic based question based on something I SAID I HAD ALREADY TRIED CHANGING IN MY QUESTION!!! Here’s my question btw in case anyone can help here before I smash up my laptop 😑:
I have a piece of code in which I am trying to read in words which have been categorised using a number and then placed in a text file in the following format "word-number-" with a new line for each word. However, despite not mixing cin>> and getline and having tried a number of methods I still cannot get it working.
So far I have attempted using a cin.ignore() call to clear any '\n' char's from the buffer, as well as checking if the file is opening in the first place (it is), and using the >> operator instead throughout my code however I could not get that working either. When I place the get line call inside the condition of the while loop, the while loop doesn't run, however when I make the while loop condition a .eof() call it will run once however when I try to print the text that has been read from the getline call it just prints a blank line.
if(file.is_open()){
while(!file.eof()){
getline(file, text, '-');
count++;
cout<<count<<endl;
cout<<text<<endl;
if(count%2 == 1){
wordBuff = text;
}else if(count%2 == 0){
if(stoi(text) == wordClass){
wordList.push_back(wordBuff);
}
}
}
file.close();
}
While I recognise there are a lot of other questions on this out there I cannot seem to get any of their solutions to work and the vast number being related to people mixing the >> operator and getline doesn't help, so any tips or solutions will be of great help

Comments
Add Comment