Code for getting multiple words in a string from user

前端 未结 5 368
独厮守ぢ
独厮守ぢ 2021-01-20 14:04

Actually i want the user to enter a line of string having multiple words in it for example \"My name is ABC\". What is the C/C++ code for this purp

5条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-20 14:31

    Following code will help you receive multiple names from user.

    #include 
    #include 
    using namespace std;
    int main()
    {
        string name[6];
        cout << "\nEnter your name : ";
        for(int i = 0; i < 6; i++)
        {
            getline(cin, name[i]);
        }
        for(int i = 0; i < 6; i++)
        {
            cout << "\nYou entered : " << name[i];
        }
        return 0;
    }
    

提交回复
热议问题