-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path01_basic_input_output.cpp
More file actions
57 lines (51 loc) · 1.54 KB
/
Copy path01_basic_input_output.cpp
File metadata and controls
57 lines (51 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
using namespace std;
int main()
{ // Basics:
// intput and output:
cout << "hello, world!" << endl;
int x;
cout << "Enter value for x: ";
cin >> x;
cout << "The value of x: " << x << endl;
// Data types:
// integer types (of multiple ranges):
int a = 3;
cout << a << endl;
long b = -9990;
cout << b << endl;
long long c = 0;
cout << c << endl;
// decimal types (of multiple ranges):
float d = 9.34;
cout << d << endl;
float e = -9; // can also store int
cout << e << endl;
double f = 89.223;
cout << f << endl;
long double g = -2392.222;
cout << g << endl;
//charater types (of multiple ranges):
char h = 'h'; // takes only single aplhabetical character in single (') quotes
cout << h << endl;
string i = "hello how";
cout << i << endl;
// NOTE:
// in this these two char and string are mainly used but there is other one that is getline, it has a different use case here is an example, so consider that:
string j;
cout << "Enter sentence for j: ";
cin >> j;
cout << j << endl;
/* OUTPUT:
hello how
Enter sentence for j: hello how are you
hello[Finished in 6.5s] */
// as you saw we wrote a 4 word sentence still we get only the first word printed, to solve this problem we have getline
string k;
cout << "Enter the sentence for k: ";
getline(cin, k);
cout << k << endl;
// getline takes the input and stores it in the vaiable and also print the output
// REMENDER: if you are running line 49 to 52 make sure line all the above code is commented out otherwise it will not work in some cases:
return 0;
}