Taking User Input in CPP

Taking User Input in CPP
Taking User Input in CPP
User Input in C++: A user input is a very useful functions in c++. It can be used dynamically enter data by user at a run time C++ program. User input can be provide different programming different functions. It is C++ programming can be used C++ User input function. I can explain different types of user input in C++.

Integer User Input: A integer user input is a whole number entered by user. Integer number is a without decimal places value. I can explain simple and easy way. Integer value can store 2 byte size in memory. 

How to Take Only Integer Input in C++

#include<iostream>
using namespace std;
int main(){
int x;
cout<<"Enter Integer Value:";
cin>>x;
cout<<"Integer Value is:"<<x;
}
============OUTPUT============
Enter Integer Value:56
Integer Value is: 56

Float User Input: A float user input is very useful data types. It can be used decimal places value. Float data type can be used 4 byte memory size. It is very simple to use in our C++ program.

How to Take Float User Input in C++

#include<iostream>
using namespace std;

int main(){

int x;
cout<<"Enter Floating Value:";
cin>>x;
cout<<"Float Value is:"<<x;
}
============OUTPUT============
Enter Floating value:78.8
Float Value is:78.8

Character User Input: A character user input is a very simple to use in C++. Character data type store a single character value in our C++ program. If you can enter only one character used in character type. 

How to Take Character User Input in C++

#include<iostream>
using namespace std;

int main(){
char x;
cout<<"Enter Character Value:";
cin>>x;
cout<<"Character Value is:"<<x;
}
============OUTPUT============
Enter Character Value: J
Character Value is: J

String User Input: A string user input is a combination of character. It is not define string data types in C++. String can be used character data type use take user input and including string.h header file in C++. 

How to Take String User Input in C++

#include<iostream>
#include<string.h>
using namespace std;
int main()
{
char name[100];
cout<<"Enter String Value:";
cin>>name;
cout<<"String Value is:"<<name;
}

============OUTPUT============
Enter String Value: Jiocoding
String Value is: Jiocoding

File User Input: A file is a mechanism to store input data in a file permanently. User input file is a very simple and easy. C++ file handling are most important because when user input enter data to store a file permanently.

How to Take Input from File in C++ Program

#include<iostream>
#include<string.h>
#include<fstream>
int main(){
ofstream f;
int id;
char name[100];
cout<<"Enter Your Id:";
cin>>x;
cout<<"Enter Your Name:";
cin>>name;
f.open("Jiocoding.txt",ios::app);
f<<"Your Id is:"<<id<<endl;
f<<"Your Name is:"<<name;
f.close();
cout<<"Data Write Successfully and Saved Jiocoding Text File";
}
============OUTPUT============
Enter Your Id:101
Enter Your Name: Jiocoding   
Data Write Successfully and Saved Jiocoding Text File

Conclusion of user input in C++

Conclusion: User Input is a dynamically enter data in run time c++ program. I can explain user input related every concept. If your any problem with user input related than you can contact me by email or comment. I can provide every solution.

Post a Comment

0 Comments