Yes. We tell you that it is indeed possible -- in more than one way.
However, what you have told does not appear to require such thing; in your example simply prints the input as is. You have to tell more and show what you have tried.
If you simply want to separate the roll number from the rest of the line (presumably the name, maybe in multiple words) then you could use the following.
(The [ ] in the output is just so that I can see what happens to leading and trailing blanks).
Not sure if this is what you are asking.
EDIT: You have just changed the question since I answered it! Please DON'T!
#include <iostream>
#include <string>
#include <sstream>
usingnamespace std;
//======================================================================
string trim( const string &s ) // remove leading and trailing blanks
{
int i = s.find_first_not_of( " " ); if ( i == string::npos ) return"";
int j = s.find_last_not_of( " " );
return s.substr( i, j - i + 1 );
}
//======================================================================
int main()
{
string line;
string rollNumber, name;
cout << "Input roll number followed by name on the same line" << endl;
getline( cin, line ); // read all input
stringstream ss( line ); // convert to a stream
ss >> rollNumber; // take first string as rollNumber
getline( ss, name ); // take rest as name (may be multiple words)
name = trim( name ); // remove blanks at start and end
cout << "Roll number is [" << rollNumber << "]" << endl;
cout << "Name is [" << name << "]" << endl;
}
//======================================================================
Input roll number followed by name on the same line
Mc1504029 Kuhshdil Kamal
Roll number is [Mc1504029]
Name is [Kuhshdil Kamal]
#include <iostream>
#include <string>
#include <vector>
usingnamespace std;
int main()
{
string line1, line2;
vector<string> students;
while( true )
{
cout << "Input roll number and name (or # to stop): ";
getline( cin, line1 );
if ( line1[0] == '#' ) break;
cout << "Input semester and year: ";
getline( cin, line2 );
students.push_back( line1 + " " + line2 );
}
cout << endl;
for ( int i = 0; i < students.size(); i++ ) cout << i + 1 << ". " << students[i] << endl;
}
Input roll number and name (or # to stop): Mc1504029 Kuhshdil Kamal
Input semester and year: fall 2016
Input roll number and name (or # to stop): BS40303 Nadeem
Input semester and year: spring 2017
Input roll number and name (or # to stop): #
1. Mc1504029 Kuhshdil Kamal fall 2016
2. BS40303 Nadeem spring 2017