Page 257 - Computer_Science_F5
P. 257
Computer Science Program Example 4.12:
The use of “cin” and “cout” commands
int main()
{
FOR ONLINE READING ONLY
int a, b;
cout<< “enter first and second number”;
cin>>a>>b;
cout<< “The product is ”<<a*b<<endl;
}
Output:
Figure 4.28: Output of cin and cout commands
The following Program Example 4.13 is for ‘getline’ command in a C++ program
which is used to solve the problem in which ‘cin’ cannot hold blank space characters.
The output is shown in Figure 4.29.
Program Example 4.13:
The use of “getline”
#include<iostream>
#include<string>
using namespace std;
int main()
{
string myname;
cout<<”What is your name? “;
getline(cin, myname);
cout<<”Hello “<<myname<<endl;
return 0;
}
Output:
Figure 4.29: Output of the ‘getline’ command
248
for Advanced Secondary Schools
Computer Science Form 5.indd 248 23/07/2024 12:33

