Reading an input with white spaces at the end

Hi everyone.
Does anyone know how can i could read an input with white spaces at the end, in C++ ?
like "blabla ".
i tried getline, cin.get, cin >>noskipws>> , each of these solutions remove this last white space

Are you sure about getline ? You can also try char toto[99]; scanf(“%[^\n]”,toto);

I did some tests, I think CG removes the last space in the last line.

Well yes i a sure, i can provide the reference of the puzzle blocking in this peculiar case. getline() removes every trailing white space at the end of an input line. Is there any solution ?

scanf with a char[99] array will not work as i need to get the exact input string to loop on every character of the string. If i have empty slots on the array the loop will do anyway 99 iterations, which i don’t want…

Scanf returns the number of readed chars. Int len=scanf(…).
Which puzzle it is ? I can take a look.

The broken editor
For the testcase 007, there is a space at the end.
You actually solved it, i am curious how. Maybe not C++ ?

I’ve just tried (and solved in c++) and getline / the default code works fine for that testcase.

Solved in c++ with getline … :thinking:

string input;
getline(cin, input);

=> and I have the space at the end of the line.

You always had this capacity to create problems where there are none kitten. <3


Well, i don’t get it. getline wasn’t working yesterday. wtf i lost like two days on stupid c++ threads for dummies -_- and now getline gives me the extra space ? This function is trolling me

Always the tools fault. :3


Yeah, i can’t be wrong, right ? :smiley: :sweat_smile:

1 Like

:sweat_smile: :sweat_smile: :sweat_smile: :sweat_smile: :sweat_smile: :sweat_smile: :sweat_smile: :sweat_smile: :sweat_smile: :sweat_smile: