std::format ???
I''m looking for a nice way to display formatted text. For example I''d like to output a date formate when i have a bunch of int''s for day, month,... Also I''d like to show long numbers with comma''s after every third character in a number... Does something like this exist? (I''ve already written a basic version myself but it seems like the kind of thing you''d find included in a language (VB did)
Chris Brodie
April 12, 2001 01:16 PM
This is the most basic thing about C++, the first thing everybody learns...
However, as for showing a comma every 3rd digit, the only thing I can think of would be converting an integer to ASCII, then manually going through and inserting commas and displaying that... why would you ever need to?
-----------------
The Goblin (madgob@aol.com)
-----------------
"Before critisizing somebody, walk a mile in their shoes. That way, when you do critisize them, not only will you be a mile away, but you''ll also have their shoes!"
#include int main(){ int month = 4; int day = 12; int year = 2001; std::cout << "The date is " << month << "/" << day << "/" << year << std::endl; return 0;}
However, as for showing a comma every 3rd digit, the only thing I can think of would be converting an integer to ASCII, then manually going through and inserting commas and displaying that... why would you ever need to?
-----------------
The Goblin (madgob@aol.com)
-----------------
"Before critisizing somebody, walk a mile in their shoes. That way, when you do critisize them, not only will you be a mile away, but you''ll also have their shoes!"
There is a way to take any type of number that has multiple digits and to seperate them into single digits. You have to use the modulus operator. Example to seperate 23 into two seperate number
variable = 22 % 100; variable should = 2
variable = 22 % 10; variable should = 3
if this doesn''t work post again saying so, right now I''m at work and I had the program at home it was a homework assignment I had a while ago, and I will try to post the correct answer, but I believe this is right. (I hope)
"There is humor in everything depending on which prespective you look from."
variable = 22 % 100; variable should = 2
variable = 22 % 10; variable should = 3
if this doesn''t work post again saying so, right now I''m at work and I had the program at home it was a homework assignment I had a while ago, and I will try to post the correct answer, but I believe this is right. (I hope)
"There is humor in everything depending on which prespective you look from."
"There is humor in everything depending on which prespective you look from."
There is a way to take any type of number that has multiple digits and to seperate them into single digits. You have to use the modulus operator. Example to seperate 23 into two seperate number
variable = 22 % 100; variable should = 2
variable = 22 % 10; variable should = 3
if this doesn''t work post again saying so, right now I''m at work and I had the program at home it was a homework assignment I had a while ago, and I will try to post the correct answer, but I believe this is right. (I hope)
"There is humor in everything depending on which prespective you look from."
variable = 22 % 100; variable should = 2
variable = 22 % 10; variable should = 3
if this doesn''t work post again saying so, right now I''m at work and I had the program at home it was a homework assignment I had a while ago, and I will try to post the correct answer, but I believe this is right. (I hope)
"There is humor in everything depending on which prespective you look from."
"There is humor in everything depending on which prespective you look from."
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement