Converting string to int for cout

In 16 lecture we use code:

cout << "Can you guess the " <<WORD_LENGTH;

but why we don’t use std::to_string ? I mean something like

#include <string> 
std::string x = std::to_string(WORD_LENGTH);
cout << "Can you guess the " <<x;
1 Like

t’s not needed so why do you want to do that?

1 Like

Because any hidden/concealed type reduction can be a potential problem for bigger project?

Assuming you mean implicit conversions, there isn’t any. There’s overloads for both of those and more.

http://en.cppreference.com/w/cpp/io/basic_ostream/operator_ltlt

Yes, implicit conversions is a right term.
Thanks for clarifying link!

Privacy & Terms