c 2b 2b char print width

Solutions on MaxInterview for c 2b 2b char print width by the best coders in the world

showing results for - "c 2b 2b char print width"
Veronica
10 Jan 2019
1
2/*
3OUTPUT
4char variable value: Programming
5-----------------------------------------------------
6[%s]       |Programming|
7[%10s]     |Programming|
8[%15s]     |    Programming|
9[%-15s]    |Programming    |
10[%15.5s]   |          Progr|
11[%-15.5s]  |Progr          |
12-----------------------------------------------------
13*/
14
15// NOTE: Specifically used for char data-types (not strings)
16
17char str[]="Programming";    // Length = 11  
18
19std::cout << "[%s]       |";
20printf("%s",str);      // Display Complete String  
21std::cout << "|\n";
22
23std::cout << "[%10s]     |";
24printf("%10s",str);    // 10 < Length: Display Complete String  
25std::cout << "|\n";
26
27std::cout << "[%15s]     |";
28printf("%15s",str);    // 15 > Length: Displays Complete String with 4 spaces Alignment:Right  
29std::cout << "|\n";
30
31std::cout << "[%-15s]    |";
32printf("%-15s",str);   // Same as Above But Left Aligned
33std::cout << "|\n";
34
35std::cout << "[%15.5s]   |";
36printf("%15.5s",str);  // 15-5 = 10 spaces and show first 5 characters Align : R    
37std::cout << "|\n";
38
39std::cout << "[%-15.5s]  |";
40printf("%-15.5s",str); // 15-5 = 10 spaces and show first 5 characters Align : L  
41std::cout << "|\n";