How to Take Multiple Input from User in C++? Last Updated : 14 Feb, 2024 Comments Improve Suggest changes Like Article Like Report 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 using loops. It will allow the user to enter the data till required. We can use any data container to store the data entered by the user. C++ Program to Take Multiple Inputs from UserThe below example demonstrates how we can take multiple inputs from a user in C++. C++ // C++ program to input multiple items #include <iostream> #include <vector> using namespace std; int main() { int n; // Input the number of elements cout << "Enter the number of elements you want to " "input: "; cin >> n; // Initialize a vector of size n vector<int> vec(n); // Input n numbers into the vector cout << "Enter " << n << " numbers: "; for (int i = 0; i < n; i++) { cin >> vec[i]; } // Output the entered numbers cout << "You entered: "; for (int i : vec) { cout << i << " "; } cout << endl; return 0; } Output Enter the number of elements you want to input: 5Enter 5 numbers: 1 2 3 4 5You entered: 1 2 3 4 5Time Complexity: O(n), where n is the number of elements you want to enter.Space Complexity: O(n) Comment More infoAdvertise with us Next Article How to Take Multiple Input from User in C++? technoayan7 Follow Improve Article Tags : C++ cpp-input-output CPP Examples Practice Tags : CPP Similar Reads Taking Input from User in R Programming Developers often have a need to interact with users, either to get data or to provide some sort of result. Most programs today use a dialog box as a way of asking the user to provide some type of input. Like other programming languages in R it's also possible to take input from the user. For doing s 7 min read How to Take Input in Array in C++? Arrays in C++ are derived data types that can contain multiple elements of the same data type. They are generally used when we want to store multiple elements of a particular data type under the same name. We can access different array elements using their index as they are stored sequentially in th 3 min read How to use getline() in C++ when there are blank lines in input? In C++, if we need to read a few sentences from a stream, the generally preferred way is to use the getline() function as it can read string streams till it encounters a newline or sees a delimiter provided by the user. Also, it uses <string.h> header file to be fully functional. Here is a sam 2 min read Printing Output in Multiple Lines in C++ This article focuses on discussing how to use cout for multi-line printing. This can be easily done using any of these two methods: Using endl.Using \n. Let's discuss each of these methods in detail. Using endl The endl statement can be used to print the multi-line string in a single cout statement. 2 min read C++ Program to Print Your Own Name Printing your own name means displaying your name on the computer screen. In this article, we will learn how to print your own name using a C++ program.ExamplesInput: name = "Anmol"Output: AnmolExplanation: Given name is printed on the output screen.Input: name = "Alex"Output: AlexExplanation: Given 3 min read How to Read and Print an Integer value in C++ The given task is to take an integer as input from the user and print that integer in C++ language. In this article, we will learn how to read and print an integer value. In the below program, the syntax and procedures to take the integer as input from the user is shown in C++ language. Standard Inp 2 min read C++ Wait for User Input Waiting for User input is common functionality in any program requiring some form of user intervention. Whether it is halting the execution to see the output produced, or is it for taking in user input, halting the execution for input is one of the most common tasks that are performed by a program. 4 min read Using return value of cin to take unknown number of inputs in C++ Consider a problem where we need to take an unknown number of integer inputs. A typical solution is to run a loop and stop when a user enters a particular value. How to do it if we are not allowed to use if-else, switch-case, and conditional statements? The idea is to use the fact that 'cin >> 2 min read Basic Input / Output in C++ In C++, input and output are performed in the form of a sequence of bytes or more commonly known as streams.Input Stream: If the direction of flow of bytes is from the device (for example, Keyboard) to the main memory then this process is called input.Output Stream: If the direction of flow of bytes 5 min read Reading Lines by Lines From a File to a Vector in C++ STL Prerequisites: STL in C++Vector in C++File handling in C++ The Standard Template Library (STL) is a set of C++ template classes to provide common programming data structures and functions such as lists, stacks, arrays, etc. It is a library of container classes, algorithms, and iterators. Vector in C 2 min read Like