You are almost there, the error is most probably1 caused because you are trying to call getline
with second parameter stringstream
, just make a slight modification and store the data within the std::cin
in a string
first and then used it to initialize a stringstream
, from which you can extract the input:
// read input string input; getline(cin, input); // initialize string stream stringstream ss(input); // extract input string name; string course; string grade; ss >> name >> course >> grade;
1. Assuming you have included:
#include <iostream> #include <sstream> #include <string> using namespace std;
Related Posts:
- std::cin.getline( ) vs. std::cin
- When and why do I need to use cin.ignore() in C++?
- Using getline() with file input in C++
- What are the rules of the std::cin object in C++?
- C++ round a double up to 2 decimal places
- Using the fstream getline() function inside a class
- Why would we call cin.clear() and cin.ignore() after reading input?
- cin >> “no operator matches these operands”
- getline() does not work if used after some inputs
- Press Enter to Continue
- cin >> “no operator matches these operands”
- Correct way to use cin.fail()
- Checking cin input stream produces an integer
- Center text in fixed-width field with stream manipulators in C++
- C++: Using ifstream with getline();
- std::cin input with spaces?
- c++ Read from .csv file
- Reading multiple lines from a file using getline()
- getline: identifier not found
- https://stackoverflow.com/questions/3865946/error-generic-array-creation
- How do I flush the cin buffer?
- Trying to use int in getline
- cin.ignore(numeric_limits
::max(), ‘\n’) - Incomplete type is not allowed: stringstream
- Using cin for char array
- How to use stringstream to separate comma separated strings [duplicate]
- Using cin to input a single letter into a char
- Multiple inputs on one line
- Why are there two different getline() functions (if indeed there are)?
- How do you clear a stringstream variable?
- Floating point exception( core dump
- Passing Arrays to Function in C++
- Return array in a function
- Regular cast vs. static_cast vs. dynamic_cast
- What is an unsigned char?
- C++ std::priority_queue uses the lambda expression
- When to use reinterpret_cast?
- How does the modulus operator work?
- Single class has a Class Redefinition Error
- Identifier not found error on function call
- Debug assertion failed. C++ vector subscript out of range
- What causes a SIGABRT fault?
- Graphics Library for C++
- ‘cout’ was not declared in this scope
- What is the difference between const int*, const int * const, and int const *?
- TranslateName() function doesn’t work on win10
- Socket Programming in C++
- warning: ISO C++ forbids variable length array
- C++ Structure Initialization
- expression preceding parentheses of apparent call must have (pointer-to-) function type
- Enum to String C++
- Random float number generation
- C++ terminate called without an active exception
- MinGW: “gcc is not recognized as an internal or external command”
- Convert Python program to C/C++ code?
- “Error: expression must have a pointer type” when using the “this” keyword
- C++ #include guards
- glm rotate usage in Opengl
- How to convert vector to array
- “non-standard syntax; use ‘&’ to create a pointer to member” error in Visual Studio 2015
- libpng warning: iCCP: known incorrect sRGB profile
- How to run valgrind with basic c example?
- initial value of reference to non-const must be an lvalue
- Typedef function pointer?
- cc1plus: error: unrecognized command line option “-std=c++11” with g++
- cannot declare variable ‘’ to be of abstract type ‘’
- Difference between ‘struct’ and ‘typedef struct’ in C++?
- Debug vs Release in CMake
- C++ Matrix Class
- How to call on a function found on another file?
- How to project a point onto a plane in 3D?
- Using C-string gives Warning: “Address of stack memory associated with local variable returned”
- generate random double numbers in c++
- Cygwin Make bash command not found
- C++ Compiler Error C2280 “attempting to reference a deleted function” in Visual Studio 2013 and 2015
- Why use pointers?
- Why I cannot cout a string?
- How do I return a char array from a function?
- How to change string into QString?
- Including .cpp files
- Class template inheritance C++
- C++ error: undefined reference to ‘clock_gettime’ and ‘clock_settime’
- Converting String to Cstring in C++
- creating dynamic array of string c++
- Two decimal places using printf( )
- error C2244 unable to match function definition to an existing declaration
- Initializing pointers in C++
- Static vs dynamic type checking in C++
- “No rule to make target ‘install'”… But Makefile exists
- How to determine the version of the C++ standard used by the compiler?
- Make / gcc cryptic error 2: how to have more information?
- REGSVR32: the module “xxxxx.dll” failed to load … dependent assembly could not be found
- What does “warning: not all control paths return a value” mean? (C++)
- Array of Linked Lists C++
- Is it still safe to delete nullptr in c++0x?
- Declaration is incompatible with type
- One or more multiply defined symbols found
- I’m getting the error “stoi is not a member of std” in myprogramminglab [duplicate]
- Template constructor in a class template – how to explicitly specify template argument for the 2nd parameter?
- C++ float array initialization