#Best way to print a string
82 messages · Page 1 of 1 (latest)
When your question is answered use !solved or the button below to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

depends on what your goals are
std::cout is the best way if you want to use streams or if you want to keep compatibility with old versions of C++
if you are using c++23 or newer you can use std::println
I personally keep large projects on c++20 still and write my own small abstraction for printing
but for small projects I use c++23/c++26 and std::println
what is this abstraction ? std::format the object the std::cout ?
so I should update to C++26 whenever possible and use std::println
C++23
yeah usually something like:
template <typename... Arguments>
void smuggle_verbose_log_line(std::format_string<Arguments...> format,
Arguments&&... arguments);
no
using older c++ versions is usually prefared for large scale projects
for better support
i still need to learn variadic templates and collapsing references 🥲
if you are just learning , trying stuff out, use 20 or try 23 if u can
c++17 if really wide support is essential
MSVC doesnt have 23 fully supported yet so im just using 20 for everything
and what about c++11
if you are in school use whatever the school uses so you dont try to use a feature that doesnt exist on an exam
its too old
too oldvery widely supported
yes
ok thanks
c++20 is generally widely supported rn
but you also wont have many good modern features
ooh
I woudent dip belowe c++17 if I were you tho
my golden standard is c++20 for big projects and c++26 for someting I can write in a day
just for convience
Thank you and let us know if you have any more questions!
This thread is now set to auto-hide after an hour of inactivity
support?
wider support between implementations
if you need it to run on old or niche machines support can be an issue
but usually it isnt
hmmm well as long as they don't care about MSVC, C++26 support is good
the older something is the less likely for a undescovered security vurnerability too
there is not a single stable compiler release with reflection or contracts
stable enough for me :P
modules are still pretty shakey from way back in c++20
especially if your running on older machines with older compilers
Mfw the support narrows before cpp11
I mean, I couldnt see an option for cpp98 on msvc
no it not
use std::print and std::println anyway
you can just pass ostream into it
thats c++23
well, c++26 is comming so
I use std::cout with std::format (C++20). std::cout has a buffer and can optimize the output stream.
Because of the buffer when debugging, std::cout can send outputs in a non-linear way. Therefore, for debugging, std::cerr is generally used, which sends outputs directly to the output.
Bruh, so std::format should only be checked at compile time.
oh, that's nothing special though
Well, I think std::cout and std::format are still a good combination. std::cout has its buffer to optimize output, and you can use std::format to improve readability.
thats what I always use accept for small projects where I use std::println
Best way to print a string
std::print(std::cout, "Something"); tho i think it already by default
nvm default is std::print(stdout, ...);
personally i use std::cout << ... + std::cerr << ... + std::clog << ... + std::cin >> ... + std::getline std::cin, ... + std::wcout + std::wcerr + std::wclog + std::wcin + std::getline std::wcin, ... + std::printf + std::fprintf stdout, ... + std::puts + std::putchar + std::putc ..., stdout + std::scanf + std::fscanf stdin, ... + std::gets_s + std::getchar + std::getc stdin + std::wprintf + std::fwprintf stdout, ... + std::putwchar + std::getwchar + std::format + std::cout + std::vformat + output stream + std::print + std::println + std::ostringstream → std::cout + std::istringstream ← std::cin + std::stringstream + std::ostream::write + std::istream::read + std::istream::get + std::istream::getline + std::istream::ignore + std::ostream::put + std::sync_with_stdio false + C stdio + mixed usage + std::basic_ostream<char> + std::basic_istream<char> specializations + std::basic_ostream<wchar_t> + std::basic_istream<wchar_t> + std::spanstream + std::basic_syncbuf + std::osyncstream + std::ranges-based input via iterators over std::cin + std::istream_iterator<T> + std::ostream_iterator<T> + std::freopen "CON", ... + std::system "echo ..." + std::streambuf
took them 40 years only
tbh personal logging library better
i mean u want to wrap the std::cout sure, want to add more functionalities sure
kinda of a win win i think
although 40 years for printf but newer is indeed crazy
Really? I use std::cout with std::format. If std::print uses std::cout as stream object it's very cool, because it's more readable, and has optimization. I'll read about this.
Yeah, std::cout has linked to stdout that is the default C output stream. Then i'll use std::print now. This has the same effect of std::cout + std::format