formatted-input

Reading formatted data with C++'s stream operator >> when data has spaces

可紊 提交于 2019-11-28 20:44:24
I have data in the following format: 4:How do you do? 10:Happy birthday 1:Purple monkey dishwasher 200:The Ancestral Territorial Imperatives of the Trumpeter Swan The number can be anywhere from 1 to 999, and the string is at most 255 characters long. I'm new to C++ and it seems a few sources recommend extracting formatted data with a stream's >> operator, but when I want to extract a string it stops at the first whitespace character. Is there a way to configure a stream to stop parsing a string only at a newline or end-of-file? I saw that there was a getline method to extract an entire line,

Reading formatted data with C++'s stream operator >> when data has spaces

匆匆过客 提交于 2019-11-27 13:11:12
问题 I have data in the following format: 4:How do you do? 10:Happy birthday 1:Purple monkey dishwasher 200:The Ancestral Territorial Imperatives of the Trumpeter Swan The number can be anywhere from 1 to 999, and the string is at most 255 characters long. I'm new to C++ and it seems a few sources recommend extracting formatted data with a stream's >> operator, but when I want to extract a string it stops at the first whitespace character. Is there a way to configure a stream to stop parsing a

problems with scanf(“%d\n”,&i) [duplicate]

巧了我就是萌 提交于 2019-11-27 07:59:47
问题 This question already has answers here : What is the effect of trailing white space in a scanf() format string? (4 answers) Closed last year . For this code: int i; scanf("%d\n",&i); I am not able to stop my program until I input two numbers. I think it is very strange ,I know when the input is suitable,the scanf will return 1. When I input "12a 'Enter'","12 'Enter'2" and so on ,it is ok,the i=12,it seems that when I input something is different int or input a 'Enter' and something another