Say if I want to display 2018 when the input is 18, how can I make it display the "20" in 2018? I tried using setfill("20") and it won't work as it's a string rather than a char. But when I used setfill('2'); it will display 2218.
Can you use setfill() to set fill 2 digits?
479 Views Asked by Yu Ting Yang At
1
There are 1 best solutions below
Related Questions in C++
- How to immediately apply DISPLAYCONFIG_SCALING display scaling mode with SetDisplayConfig and DISPLAYCONFIG_PATH_TARGET_INFO
- Why can't I use templates members in its specialization?
- How to fix "Access violation executing location" when using GLFW and GLAD
- Dynamic array of structures in C++/ cannot fill a dynamic array of doubles in structure from dynamic array of structures
- How do I apply the interface concept with the base-class in design?
- File refuses to compile std::erase() even if using -std=g++23
- How can I do a successful map when the number of elements to be mapped is not consistent in Thrust C++
- Can std::bit_cast be applied to an empty object?
- Unexpected inter-thread happens-before relationships from relaxed memory ordering
- How i can move element of dynamic vector in argument of function push_back for dynamic vector
- Brick Breaker Ball Bounce
- Thread-safe lock-free min where both operands can change c++
- Watchdog Timer Reset on ESP32 using Webservers
- How to solve compiler error: no matching function for call to 'dmhFS::dmhFS()' in my case?
- Conda CMAKE CXX Compiler error while compiling Pytorch
Related Questions in DATE
- Using JQuery Date Slider
- Get Type Error when using .countDocuments with mongoDB
- Gsheet - Automatically send an email using a date & time in a Cell
- Market share growth versus last month, last year
- Convert date string into a number in Python
- Date formatting "yyyy-MM-dd hh:mm:ss +0000" to "dd MMM" in swift
- How does Big Query differentiate between a day and month when we upload any CSV or text file?
- Event_date reference in CTE
- Laravel Nova 4 format date in BelongsTo field
- how to count days elpased between each interval using mySQL?
- MariaDB incorrect dates
- Date issue - how do I parse date in this SQL
- Countdown to varying payday in Javascript
- Can I have a static ISO8601DateFormatter with specific formatOptions in Swift?
- Date Format mdy vs dmy
Related Questions in FORMATTING
- Calling ToString with a nominated format returns Char rather than String
- How do I use Poor Man's T-SQL Formatter in SSMS v20?
- Auto style text in flutter
- Have ISODD(SUMPRODUCT(1/COUNTIF ignore all blank cells
- Python library to display interview questions results (stored in excel)
- All styling is being removed from tables
- Highlight column based on current date and time
- ORACLE: Tabs used for indentation converted to spaces in stored procedure when executing through DSN connection
- Is there a 'bottom-to-top' equivalent of the unicode 'rtl override'?
- Write text to excel sheet using python but with different formats in a single cell
- how to format with double quotes using f-format in python?
- How to use 4 spaces formatting for indentation in VSCode for Volar through Vue - Official extension in .vue files?
- I am receiving a color formatting error when trying to run a Crystal Report in Personify
- how to Customize autoformatting of C# Code in visual Studio 2022
- How do I change the way my brace completion is handled in Visual Studio 2022 for Unity when coding in HLSL?
Related Questions in OSTREAM
- How would I make two ways to output something with <<?
- The problem is writing operator overloading << and >> using templates
- How to define an ostream function of an inner struct of a templated outer struct?
- No match for ‘operator<<’ (probably due to my version of c++/gcc?)
- Is it safe to mix IO styles on a file with Posix file control (fcntl) and std::filebuf in C++?
- Inherited CombinedStream object causing segmentation fault
- How to save continious data values in a file with fstream in C++?
- C++ function call in cout leads to "Reference to non-static member function must be called"
- C++ OOP overloading ostream problem at printing
- Is there a way to redirect string output in c++
- Pybind11 C++ python standard output from ostream (Jupyter notebook)
- Problem implementing a << operator for a class
- Iterating through custom map && handling several streams
- why does passing a nullptr value to an ostream stop printing to stdout?
- How to be sure of writing the whole string to file at once in C++
Related Questions in IOMANIP
- How does std::setprecision affect general floating-point formatting?
- how does capstone disassemble instructions? does it dissassemble it to raw assembly code?
- Extra space/char when using setfill() and setw(), Output changed after printing again
- How do i make setprecision effect only one variable and not all in my code
- How do I get my Hex String to include intermediate zeroes in C++?
- How do the std::left and std::right I/O manipulators work, and why are they used in the way they are used?
- Can't understand how to make istream manipulator
- noskipws on char extraction from StringStream causes it to not work with subsequent string extractions
- no match for 'operator<<' (operand types are 'std::ostream {aka std::basic_ostream<char>}' and 'std::_Setfill<const char*>')
- Can std::hex input format support negtive int16_t hex string with two's complement notation such as `ffff` for `-1`?
- Remove number demical and turn into hexadecimal
- Whats the use of std::cin >> setprecision(n)?
- What is the purpose of the setprecision() used in this C++ program?
- I cant seem to get the amount of decimals right using setprecision c++
- setprecision(2) value not working in if statement even when the conditions are true
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular # Hahtags
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
The formatting facility
setfill()is designed to fill the empty space by repeating one single char. So it is not possible to obtain this effect, using a string.For time formatting, you'd have the possibility to use
put_time()with a formatting string to indicate the desired format (e.g.Yfor2018andyfor18), provided you have a real date (so year 2018) passed in atmstructure.In your case, you could try something like:
But a better approach would be to either ensure that the date is entered on 4 digits (this will avoid you the future bug of the year 2100), or use some function for doing that, so that --if needed-- your future you could easily find the delicate places in your code.