Различные способы печати строк в C++: изучение различных методов вывода

В C++ существует несколько способов печати строки. Вот несколько разных методов:

  1. Использование оператора cout:

    #include <iostream>
    using namespace std;
    int main() {
       string myString = "Hello, world!";
       cout << myString << endl;
       return 0;
    }
  2. Использование функции printf из библиотеки C:

    #include <cstdio>
    int main() {
       const char* myString = "Hello, world!";
       printf("%s\n", myString);
       return 0;
    }
  3. Использование функции puts из библиотеки C:

    #include <cstdio>
    int main() {
       const char* myString = "Hello, world!";
       puts(myString);
       return 0;
    }
  4. Использование функции записи из стандартной библиотеки C++:

    #include <iostream>
    #include <unistd.h>
    int main() {
       const char* myString = "Hello, world!";
       write(1, myString, strlen(myString));
       return 0;
    }
  5. Использование класса stringstream:

    #include <iostream>
    #include <sstream>
    using namespace std;
    int main() {
       string myString = "Hello, world!";
       stringstream ss;
       ss << myString;
       cout << ss.str() << endl;
       return 0;
    }