answersLogoWhite

0

We don't have to do anything fancy to implement this, we can simply extract the character sequence directly into a standard string object. By default, all leading whitespace characters (space, tab and newline) are ignored and extraction ends when the next whitespace or newline character is encountered in the character sequence.

#include<iostream>

#include<string>

int main () {

std::string s {};

std::cout << "Enter some text:\n";

std::cin >> s;

std::cout << "The first word input was:\n";

std::cout << s << std::endl;

}

Output:

Enter some text:

one two three

The first word input was:

one

User Avatar

Wiki User

9y ago

What else can I help you with?