#std::getline() Windows reading "\r\n"

26 messages · Page 1 of 1 (latest)

scarlet violetBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

north heart
#

\r\n is what happens when you press return

#

(enter)

#

CRLF

#

no

#

std::getline gets the newline character too i think

#

getline reads until and including a new line character basically

#

remove the last two characters from the string(not the null terminating character tho)

#

do you use std::string?

#

well then just do

#

.pop_back() twice if it really bothers you

#

or overload operator>> for Book in a way that it only stops when you hit a new line and doesn't stop at backspaces

scarlet violetBOT
#

Thank you and let us know if you have any more questions!

This thread is now set to auto-hide after an hour of inactivity

#

@deft narwhal

Please Do Not Delete Posts!

Please don't delete forum posts. They can be helpful to refer to later and other members can learn from them. In the future you can use !solved to close a post and mark a post as solved.

north heart
#

hmm weird

#

for me, it doesn't include the \r\n thonk

#

i hate strings and text in programming tho

#

you have to worry about encoding, newline difference, etc

scarlet violetBOT
#

@deft narwhal Has your question been resolved? If so, type !solved :)

north heart
#

yeah probably because std::cin throws away whitespaces or something like that

#

hmm, it is empty even with a file

#

vsc doesnt have anything to do with this tho

#

tho i set Visual studio to use LF, so my in.txt only has a \n at the end

#
int main() {
    std::string line;
    std::ifstream in("in.txt");
    std::getline(in, line);
    return 0;
}