We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
They are basically going through each character and reprinting it; however, whenever they come to a comma, they instead print a '\n', creating the new line.
cout << (c != ',' ? c : '\n') takes advantage of the ternary operator x ? y : z, which follows the process of validating x, and passing back y if it is true, or z if it is not. It basically rewrites "44,23,45" as "44\n23\45".
StringStream
You are viewing a single comment's thread. Return to all comments →
They are basically going through each character and reprinting it; however, whenever they come to a comma, they instead print a
'\n'
, creating the new line.cout << (c != ',' ? c : '\n')
takes advantage of the ternary operatorx ? y : z
, which follows the process of validatingx
, and passing backy
if it is true, orz
if it is not. It basically rewrites"44,23,45"
as"44\n23\45"
.Read more on the Ternary Operator.