Basic Input/Output
- What is the output of this program?
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main ()
{
string str;
float p = 0;
int q = 0;
cout << "Enter item price: ";
getline (cin, str);
stringstream(str) >> p;
cout << "Enter item quantity: ";
getline (cin, str);
stringstream(str) >> q;
cout << "Total item price: " << p * q << endl;
return 0;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
In this program, We are getting the input on runtime and manipulating the value.
- What is the output of this program?
#include <iostream>
#include <ios>
#include <istream>
#include <limits>
using namespace std;
template <typename CharT>
void ignore_line ( basic_istream& in )
{
in.ignore ( numeric_limits:: max(), in.widen ( '\n' ) );
}
int main()
{
cout << "First Any Number or String: ";
cin.get();
cout << "Clearing cin Data.\n";
cin.clear();
ignore_line ( cin );
cout << "All done Smoothly.\n";
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: E
In this program, We are getting the input and clearing all the values.
- What is the output of this program?
#include <iostream>
using namespace std;
int main( )
{
char line[50];
cin.getline( line, 50, 'p' );
cout << line;
return 0;
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
The program will store all strings entered and will print them only when the character ‘p’ is encountered.
- How many parameters are there in getline function?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: E
There are two or three parameters in getline() function. They are a pointer to an array of characters and maximum number of characters and an optional delimiter.
- What can be used to input a string with blank space?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
If a user wants to input a sentence with blank spaces, then he may use the function getline.