M
M
MaximTimoff2022-03-06 07:33:38
C++ / C#
MaximTimoff, 2022-03-06 07:33:38

Difference between the two designs?

What is the difference factor between these two?

cout << "Hello, World!";

// и

cout << string("Hello, World!");

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sticky Rain, 2022-03-06
@MaximTimoff

cout << "Hello, World!";uses the operator<< overload associated with a null-terminated "hello" character array, which is a const char[6], to a const char* when passed as an operator<< argument:

template< class CharT, class Traits >
basic_ostream<CharT,Traits>& operator<<( basic_ostream<CharT,Traits>& os,
                                         const char* s );

cout << string("Hello, World!"); использует оператор<< перегрузка для работы со строками. 
string - это typedef для std::basic_string<char, std::char_traits<char>, std::allocator<char>>.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question