C ++ использует cout для печати cin >> records - PullRequest
0 голосов
/ 29 апреля 2020

Я хочу здесь, чтобы напечатать результат, sname; пароль; et c, но программа вылетает.

#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
string enter1;
string s;
string sname;
string email;
string password;

string ma()
{
    {
        for (int i = 0; i < 1; i++)
        {
            cout << "Welcome to our software :D " << endl;
            cout << "Menu :                            " << endl;
            cout << "Enter Your Name :                 " << endl;
            cout << "Enter Your Email:                 " << endl;
            cout << "Enter Your password :             " << endl;
            cout <<"Enter n if you want to print all those results"<<endl;
            cout << "which number ! :";
            cin >> s;
        }
    }

    if (s == "1")
    {
        cout << "Enter Your Name Mate : ";
        cin >> sname;
        ma();
    }
    if (s == "2")
    {
        cout << "Enter Your Email:                 ";
        cin >> email;
        ma();

    }
    if (s == "3")
    {
        cout << "Enter Your Password:                 ";
        cin >> password;
        ma();
        if (s == "n")
        {
            cout << sname;
            cout << email;
            cout << password;
        }

    }
}
int main(int argc, char **argv)
{

    cout << "Write [e] if you want to open the program :";
    cin >> enter1;
    if (enter1 == "f")
    {
        ma();
    }
    else
    {
        cout << "You Choose to close the program ......";
        exit(EXIT_FAILURE);
    }
    return 0;
}

результат примерно такой:

Write [e] if you want to open the program :f
Welcome to our software :D 
Menu :                            
Enter Your Name :                 
Enter Your Email:                 
Enter Your password :             
which number ! :1
Enter Your Name Mate : adem  
Welcome to our software :D 
Menu :                            
Enter Your Name :                 
Enter Your Email:                 
Enter Your password :             
which number! :2
Enter Your Email:  adem07@gmail.com
Welcome to our software :D 
Menu :                            
Enter Your Name :                 
Enter Your Email:                 
Enter Your password :             
which number! :3
Enter Your Password:                 dsaddsa
Welcome to our software :D 
Menu :                            
Enter Your Name :                 
Enter Your Email:                 
Enter Your password :             
which number ! :n

RUN FINISHED; Segmentation fault; real time: 24s; user: 0ms; system: 0ms
...