-->
Showing posts with label WAp to input string. Show all posts
Showing posts with label WAp to input string. Show all posts

WAp to input string

// program to understand string input in C++ using string data type
#include<iostream>
#include<stdlib.h>
using namespace std;
int main()
{
    string name;    //string data type to accept string. We can not write identifier value i.e name[30].
                    // If we write then we should use char name[30].
    system("cls");  // clears the screen
    cout<<"enter name"<<endl;// cout object to print message.<< is also called insertion operator.
    getline(cin,name);     // accepts name using 'get from' operator (>> or extraction operator) with space.
    cout<<"name="<<name<<endl;// prints input values/string/name.
    cout<<"enter name again"<<endl;//prints the literal
    cin>>name;// accepts name without space.
    cout<<"name="<<"without space is:-"<<name;//prints name
    return 0;

}