![]() |
In C++, strings are used to store textual data. While working with user input, we often may need to take multiple string inputs in a single line only. In this article, we will learn how to take multiple string inputs in a single line. Example Input: Hi,Geek,Welcome,to,GfG delimiter = ',' Output: String 1: Hi String 2: Geek String 3: Welcome String 4: to String 5: GfG Take Multiple String Inputs in C++To take multiple string inputs in a single line, we can use the std::getline() function with a user-defined delimiter (like space, semicolon, comma, etc) that indicates the end of one string. We can then tokenize that string using the stringstream and geline() function. C++ Program to Take Multiple String InputsC++
Output Enter multiple strings separated by a custom delimiter: Hi,Geek,Welcome,to,GfG Enter the delimiter: , String 1 Hi String 2 Geek String 3 Welcome String 3 to String 4 GfG |
Reffered: https://www.geeksforgeeks.org
C++ |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 14 |