Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Code for getting multiple words in a string from user [closed]

Tags:

c++

c

string

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 purpose?

Thanks in advance

like image 894
hkasera Avatar asked Aug 28 '26 09:08

hkasera


1 Answers

#include<iostream>
#include<string> 
using namespace std;

int main(){

string testString;
getline(cin, testString);

{

if you have

cin >> otherVariables

You need to delete the newline buffer in between by adding:

cin.ignore()

You should have something like:

string userMessage;
cin.ignore();
getline(cin, testString);
like image 150
Richie Flores Avatar answered Aug 29 '26 22:08

Richie Flores



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!