How to Take Multiple String Inputs in a Single Line in C++? Last Updated : 08 Feb, 2024 Comments Improve Suggest changes Like Article Like Report 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: GfGTake 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 Inputs C++ // C++ program to take multiple string inputs in a single // line. #include <iostream> #include <sstream> #include <string> using namespace std; int main() { string input; string delimiter; cout << "Enter multiple strings separated by a custom " "delimiter: "; getline(cin, input); // Prompt the user to enter a custom delimiter cout << "Enter the delimiter: "; getline(cin, delimiter); // Using stringstream to tokenize the input based on the // custom delimiter stringstream ss(input); string token; int i = 1; while (getline(ss, token, delimiter[0])) { // Process each string token cout << "String " << i << " " << token << endl; i++; } return 0; } 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 Comment More infoAdvertise with us Next Article How to Take Multiple String Inputs in a Single Line in C++? chalti Follow Improve Article Tags : C++ Programs C++ cpp-input-output cpp-string cpp-vector CPP Examples +2 More Practice Tags : CPP Similar Reads How to Take Multiple Line String Input in C++? In C++, taking string input is a common practice but the cin is only able to read the input text till whitespace. In this article, we will discuss how to read the multiple line of text input in C++. For Example, Input:Enter Your Text: This is amultiline text.Output:You Have Entered:This is amultilin 2 min read How to Read Multiple Numbers from a Single Line of Input in C++? In C++, when working with user inputs we often need to take input of multiple numbers from a user in a single line. In this article, we will learn how to read multiple numbers from a single line of input in C++. Example Input: 1 7 0 4 6 8 Output: Entered Number: 1, 7, 0, 4, 6, 8Take Multiple Numbers 2 min read How to Take Long String Input With Spaces in C++? In C++, we often take long strings with a lot of characters as inputs with spaces but if we use cin then our input gets terminated as soon as whitespace is encountered. In this article, we will discuss how to take long strings with spaces as input in C++. Take Long String Input With Spaces in C++To 2 min read How to Handle Multiple String Inputs with Spaces in C++? In C++, strings are a sequence of characters that might contain spaces in many cases but we can read only the input text till whitespace using cin. In this article, we will learn how to handle multiple string inputs with spaces in C++. Example: Input:Enter multiple strings:String1String2Output:You E 2 min read How to Reverse a String in Place in C++? In C++, reversing a string is a basic operation in programming that is required in various applications, from simple and complex algorithms. Reversing a string in place involves changing the characters of the string directly without using input-dependent additional storage. In this article, we learn 2 min read How to Insert a Pair in Multimap in C++? In C++, we have multimap which is used to store key-value pairs like a map but multimap can have multiple values for the same key. In this article, we will learn how to insert a pair into a multimap in C++. Example Input: myMultimap = { {1, "this"}, {2,"is"}} myPair = {2, "was"}; Output: myMultimap 2 min read How to Read a Line of Input Text in C++? In C++, we often need to take input from the user by reading an input text line by line but the cin method only takes input till whilespace. In this article, we will look at how to read a full line of input in C++. For Example, Input: This is a text.Output: Entered Text: This is a text.Taking a Line 2 min read How to Take Multiple Input from User in C++? In C++, we use cin when we want to take input from the user. We often also need to take more than one input at a time. In this article, we will learn how to take multiple inputs in C++. Take Multiple Inputs from a User in C++To take multiple inputs from users, we can repeatedly use the std::cin usin 2 min read How to Concatenate Multiple C++ Strings on One Line? In C++, strings are used to store a sequence of characters. The combination of multiple strings into a single one is called Concatenation. In this article, we will learn how to concatenate multiple strings in C++. Example Input: str1="Hello!"str2="Geek"str3="Welcome to GfG"Output:Hello! Geek Welcome 1 min read How To Insert Multiple Key-Value Pairs Into a Multimap in C++? In C++, a multimap is similar to a map that stores the data in the key-value format and it also allows us to store duplicate keys for the same value. In this article, we will learn how to insert multiple Key-Value pairs efficiently into a multimap. Example: Input: multi_map = {{"Manas","Singing" }, 2 min read Like