mercredi 29 septembre 2021

How would I write a program that reads from a standard input and outputs only 6 characters to a line?

For example if the input was:

My name is Alex and
I also love coding

The correct output should be:

1:My nam  
1:e is A
1:lex an
1:d
2:I also 
2: love 
2:coding                         

So far I have this

   int  main () {
     string i;
     i.substr(0,6);
     while (getline(cin, i)){
       cout << i << endl;
     }  
   }

Aucun commentaire:

Enregistrer un commentaire