how to read all the elements of input, Not only before space. Как считать все символы в строку включая пробелы | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
0

how to read all the elements of input, Not only before space. Как считать все символы в строку включая пробелы

how to read all the elements of input, Not only before space. cin.getline dont works. Как считать все символы в строку включая пробелы. cin.getline не работает

14th Dec 2022, 2:01 PM
technocat
technocat - avatar
3 Antworten
+ 3
What kind of input are you trying to read? can you save the code and share the link in post Description for a clearer view of the problem?
14th Dec 2022, 3:41 PM
Ipang
+ 1
You could try using it this way, getline(cin, variable name) instead of cin.getline. It might help.
15th Dec 2022, 8:14 AM
Bloody Halos
Bloody Halos - avatar
0
Thought of something that might also help, cin.getline takes a char string or C style type if I recall correctly. Like a char array, such as char phrase[12], 12 chars being hello world and null terminating char \0, which marks end of C style string Cin.getline second parameter takes an int value of max chars to take in, such as the 12. Both versions also have a third parameter , defaulted to newline (\n). This is what it reads to, can be other chars as well, like a '!' for instance.
15th Dec 2022, 1:29 PM
Bloody Halos
Bloody Halos - avatar