fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int widthValue = 4;
  6. char sentence[ 10 ];
  7.  
  8. cout << "Enter a sentence:" << endl;
  9. cin.width( 5 ); // input only 4 characters from sentence
  10.  
  11. // set field width, then display characters based on that width
  12. while ( cin >> sentence )
  13. {
  14. cout << "|";
  15. cout.width( widthValue++ );
  16. cout << sentence << "|" << endl;
  17. cin.width(5); // input 5 more characters from sentence
  18. } // end while
  19. return 0;
  20. } // end main
  21.  
Success #stdin #stdout 0s 3460KB
stdin
jackdaws love my big sphinx of quartz
stdout
Enter a sentence:
|jack|
| daws|
|  love|
|     my|
|     big|
|     sphi|
|        nx|
|         of|
|        quar|
|           tz|