dimanche 26 novembre 2017

Is there any way to split this function apart and insert spaces?

Let's say I needed to output an address to the screen in the following format(where "-" are spaces):

Address: 1234 Elm St.
------------ Apartment # 2 Rear
------------ Anytown, NV 12345-6789

This is some example code that defines a free function (printAddress) that will print the address to the screen. I cannot alter the code for the printAddress function in any way.

#include <iostream>
#include <iomanip>

using namespace std;

void printAddress( );

int main( )
{

    cout << "Address: ";
    printAddress ( );

    return 0;
}

void printAddress( ) 
{
    cout << "1234 Elm St." << endl;
    cout << "Apartment #2 Rear" << endl;
    cout << "Anytown, NV 12345-6789" << endl;
};

As of right now, the output of this code is:
Address: 1234 Elm St.
Apartment #2 Rear
Anytown, NV 12345-6789

I was wondering if it is possible to somehow split the function apart to insert those spaces on the second and third lines and make everything line up. Any ideas? Or is this impossible? I would really appreciate any help. Thanks!

Aucun commentaire:

Enregistrer un commentaire