📜  c++ void to avoid functions - C++ 代码示例

📅  最后修改于: 2022-03-11 14:44:52.993000             🧑  作者: Mango

代码示例1
/*The following example collects user data and formats it using seperate void
statements */
#include 
#include 
#include 
#include 

using namespace std;

// function declarations
void inputData();
void displayData();

string name, addr1, addr2, postalCode;
// the main method1
int main()
{
    inputData();
    displayData();

    return 0;
}

// the first function definition
void inputData()
{
    cout << "Kindly provide your address details \n"
         << "Name: ";
    getline(cin, name);
    cout << "Address1: ";
    getline(cin, addr1);
    cout << "Address2: ";
    getline(cin, addr2);
    cout << "PostalCode: ";
    getline(cin, postalCode);
}

// the second function definition
void displayData()
{
    //system("cls"); exists for DOS or cmd windows
    system("cls"); //system("clear") for Linux or MacOS
    cout << name
         << "\n"
         << addr1
         << "\n"
         << addr2
         << "\n"
         << postalCode << endl;
}