Login
|
Signup
langref.org
-
cpp
add..
all
clojure
csharp
erlang
fantom
fsharp
go
groovy
haskell
java
ocaml
perl
php
python
ruby
scala
Home
All
Solved
Unsolved
Strings
Numbers
Regex
Lists
Maps
Structure
Files
Dates
OOP
Networking
XML
Algorithms
Misc
Parallel
View Problem
Numbers
Output
Left Space pad a number
Given the number 73 left pad it to 10 characters
" 73"
cpp
C++/CLI .NET 2.0
String^ formatted = Convert::ToString(73)->PadLeft(10);
using namespace System;
int main()
{
String^ formatted = Convert::ToString(73)->PadLeft(10);
Console::WriteLine(formatted);
}
cpp
C++/CLI .NET 2.0
String^ formatted = String::Format("{0,10:D}", 73);
using namespace System;
int main()
{
String^ formatted = String::Format("{0,10:D}", 73);
Console::WriteLine(formatted);
}
cpp
std::printf("%10d\n", 73);
#include <cstdio>
int main()
{
std::printf("%10d\n", 73);
}
cpp
std::ostringstream os;
os << std::setw(10) << std::setfill(' ') << 73 << std::ends;
std::cout << os.str() << std::endl;
#include <iostream>
#include <sstream>
#include <iomanip>
int main()
{
std::ostringstream os;
os << std::setw(10) << std::setfill(' ') << 73 << std::ends;
std::cout << os.str() << std::endl;
}
cpp
std::cout << boost::format("%|10|") % 73 << std::endl;
#include <iostream>
#include "boost/format.hpp"
int main()
{
std::cout << boost::format("%|10|") % 73 << std::endl;
}
Submit a new solution for
cpp
There are 23 other solutions in
additional
languages (
clojure
,
csharp
,
erlang
,
fantom
...)