Discussion:
Modern C++
Add Reply
Student Project
2024-11-29 05:49:38 UTC
Reply
Permalink
Which compiler is currently able to compile this two code snippets:

std::vector<int> v = {1, 2, 3, 4, 5};
std::println("{}", v);


Suppose you want it to be centered in a line of 40 characters, with
underscore characters around it:

std::vector<int> v = {1, 2, 3, 4, 5};
std::println("{:_^40}", v);
// ____________[1, 2, 3, 4, 5]_____________


Source:
<https://isocpp.org/blog/2024/11/having-fun-with-modern-cpp-daniel-lemire>

Thank you for reading this and possible solution.
wij
2024-11-29 07:21:57 UTC
Reply
Permalink
Post by Student Project
std::vector<int> v = {1, 2, 3, 4, 5};
std::println("{}", v);
g++ 13.2.1 does not compile.
Post by Student Project
Suppose you want it to be centered in a line of 40 characters, with
std::vector<int> v = {1, 2, 3, 4, 5};
std::println("{:_^40}", v);
// ____________[1, 2, 3, 4, 5]_____________
<https://isocpp.org/blog/2024/11/having-fun-with-modern-cpp-daniel-lemire>
Thank you for reading this and possible solution.
IMO, such funciion is unnecessary, esp. inventing it to add burden to programmer.

There are lots of I/O formatting problems.
The basic solution is writing your own 'printf', or atoi,... (all are simple)

There are already lots of printf examples for students, why this 'new' one?
red floyd
2024-11-29 20:27:06 UTC
Reply
Permalink
Post by wij
Post by Student Project
std::vector<int> v = {1, 2, 3, 4, 5};
std::println("{}", v);
g++ 13.2.1 does not compile.
Post by Student Project
Suppose you want it to be centered in a line of 40 characters, with
std::vector<int> v = {1, 2, 3, 4, 5};
std::println("{:_^40}", v);
// ____________[1, 2, 3, 4, 5]_____________
<https://isocpp.org/blog/2024/11/having-fun-with-modern-cpp-daniel-lemire>
Thank you for reading this and possible solution.
IMO, such funciion is unnecessary, esp. inventing it to add burden to programmer.
There are lots of I/O formatting problems.
The basic solution is writing your own 'printf', or atoi,... (all are simple)
There are already lots of printf examples for students, why this 'new' one?
He's asking us to do his homework.

Loading...