![]() |
| Taking User Input in CPP |
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> 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++
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++
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++
{ 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> 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 |

0 Comments