Receive multiple entries separated by C++ string spaces

Asked 2 years ago, Updated 2 years ago, 25 views

In C language,

char arr1[10], arr2[10];

scanf("%s %s", arr1, arr2 );

It was possible, but I don't know how to do it in c++.

getc, getchar

Without using your back

std::cin <<

Is there a way to use it only?

c++

2022-09-22 19:52

1 Answers

#include <iostream>
#include <string>

using namespace std;

int main(void)
{
    string s1, s2;
    cin >> s1 >> s2;
    cout << s1 << "\n" << s2 << endl;

    return 0;
}

sin also divides the input by space.


2022-09-22 19:52

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.