#include <iostream>
#include <cstring>
int main()
{
using namespace std;
//for (cin>>x; x==0; cin>>x)
//----------------------------------//
//for (char ch = 'a'; ch <= 'z'; ch++)
// cout<<ch;
char word[5] = "?uck"; //we need 5 cause \0
for (char ch = 'a'; strcmp(word,"fuck"); ch++) {
cout << word << endl;
word[0] = ch;
}
cout <<"After : "<< word << endl;
return 0;
}
Test_2
#include <iostream>
#include <ctime>
int main()
{//当然我看不懂这个程序= =
using namespace std;
//while (name[i] != '\0') == while (name[i])
cout << "Enter the delay time ,in seconds : ";
float secs;
cin >> secs;
clock_t delay = secs * CLOCKS_PER_SEC;
cout << "Starting\a\n";
clock_t start = clock();
while (clock() - start < delay)
;
cout << "done\a\n";
return 0;
}
for中可声明局部变量,while不阔以。
延时循环可还行。该程序以系统时间单位为单位(而不是秒),避免了在每轮循环中将系统时间转换为秒。
Test_3
#include <iostream>
#include <ctime>
int main()
{
using namespace std;
int number[5] = { 1,2,3,4,5 };
for (int x : number) {
cout << x << std::endl;
}
for (int& x : number) {
x *= 2;
}
for (int x : number) {
cout << x << std::endl;
}
for (int y : {5, 4, 3, 2, 1}) {
cout << y << " ";
}
cout << '\n';
}
这个是目前我看不懂的操作,貌似是因为容器?基于范围的for循环。
Test_3
#include <iostream>
int main()
{
using namespace std;
char ch;
int count = 0;
cout<<"Enter your fucking number fuck!"<<endl;
cin >> ch;
while (ch != '#') { //fuck you#hiahai
cout << ch;
count++;
cin >> ch; //fuckyou
}
cout << endl << count << " Has been read" << endl; //7 Has been read
}
cin读取char和其他类型一样,会忽略空格和换行,所以空格没有被回显,也没有被计数!!!
发送给cin的输入被缓冲,amazing!!!因此可以在#后面继续输入。
Test_4
#include <iostream>
int main()
{
using namespace std;
char ch;
int count = 0;
cout<<"Enter your fucking number fuck!"<<endl;
cin.get(ch);
while (ch != '#') { //fuck you the first
cout << ch; //fuck you the second#woc
count++;
cin.get(ch); //fuck you the first
} //fuck you the second
cout << endl << count << " Has been read" << endl; //38 Has been read
}
通常我们使用 cin.gei(ch) 或者 cin.get(name,20);
Test_5
cin.get(ch);
while (cin.fail()== false) {
cin.get(ch);
}