#include<climits>
#include<cstdio>
#include<iostream>
#include<vector>
#include<array>
#include<string>
#include<ctime>
using namespace std;
struct MyStruct
{
int type;
double num;
union
{
int id_int;
float id_float;
};
};
enum Number { one, two, three, four};
int main()
{
printf("%d\n", INT_MAX);
printf("int:%d, long long:%d\n", sizeof(int), sizeof(long long));
int test1{};
int test2 = {};
int test3 = 42;
cout << "dec:" << test3 << endl;
cout << oct;
cout << "oct:" << test3 << endl;
cout << hex;
cout << "hex:" << test3 << endl;
cout << dec;
cout.put('M');
cout.put('\n');
char ch = '\n';
cout << "'\\n': " << int(ch) << endl;
int password;
cout << "Please Enter Password:________\b\b\b\b\b\b\b\b";
cout << endl;
cout << "g\u00E2" << endl;
wchar_t wch = L'P';
wcout << "wchar_t: " << wch << endl;
vector<vector<int>> t_vec;
vector<int> t_vec1 = { 1,2,3,4,5 };
auto pv = t_vec.begin();
t_vec.push_back(t_vec1);
cout << t_vec[0].size() << endl;
char* str = new char[8];
str[0] = 'a';
str[1] = 'b';
str[2] = 'c';
str[3] = 'd';
str[4] = '\0';
cout << str << endl;
char str1[] = "HelloWorld!";
char str2[12] = "HelloWorld!";
char str3[12];
cout << "Input String: ";
(cin >> str3).get();
cout << "strlen: " << strlen(str3) << endl;
cout << "sizeof: " << sizeof(str3) << endl;
string str4("aaaaa");
string str5("bbbbb");
int len_str2 = strlen(str2);
int len_str4 = str4.size();
cout << "getline(cin,str5): ";
getline(cin, str5);
cout << str5 << endl;
MyStruct ms;
ms.id_int = 10;
int* pt2 = new int;
*pt2 = 100;
vector<int> vc(5);
array<int, 5> ai;
int x = 1;
cout << (x > 3) << endl;
cout.setf(ios_base::boolalpha);
cout << (x > 3) << endl;
cout << x << ++x << x << ++x << endl;
cout << x << x++ << ++x << x++ << endl;
/*char word[] = "word";
cout << word == "word" << endl;*/
string word1 = "";
bool flag = word1 == "word";
cout << "Wait 1s......" << endl;
int delay = 1 * CLOCKS_PER_SEC;
clock_t start = clock();
while (clock() - start < delay)
;
cout << "Input A String(End with #): ";
cin >> ch;
while (ch != '#')
{
cout << ch;
cin >> ch;
}
cout << endl;
cout << "Input A String(End with #): ";
cin.get(ch);
while (ch != '#')
{
cout << ch;
cin.get(ch);
}
cout << endl;
cout << "Input A String(End with EOF): ";
cin.get(ch);
while (cin.fail() == false)
{
cout << ch;
cin.get(ch);
}
cout << endl;
cout << "continue input: ";
cin.clear();
cin.get(ch);
cout << ch << endl;
return 0;
}
#include<cctype>
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
char ch = 'a';
cout << isalpha(ch) << endl;
cout << ispunct(ch) << endl;
cout << islower(ch) << endl;
cout << char(toupper(ch)) << endl;
ch = ',';
cout << ispunct(ch) << endl;
cout << isdigit(ch) << endl;
ch = '\n';
cout << isspace(ch) << endl;
int type = 1;
switch (type)
{
case 1:cout << 1 << endl;break;
case 2:cout << 2 << endl;break;
default:cout << "no" << endl;
}
ofstream myFile;
myFile.open("test.txt");
myFile << "Yes, this is my first file!\n";
cout.precision(2);
myFile.precision(2);
double d = 112.1009;
myFile << d;
myFile.close();
ifstream inFile;
inFile.open("test.txt");
if (!inFile.is_open())
{
exit(0);
}
char line[100];
inFile.get(line, 100);
float f;
inFile >> f;
cout << "EOF:" << inFile.eof() << endl;
inFile.close();
cout << line << endl;
cout << f << endl;
return 0;
}