……学很少,学很慢还是比不学强点是吧,救命
昨天不是很懂<<,>>
输入输出
iostream, 输入流 istream 输出流ostream,COUT,CIN,CERR,CLOG
#include <iostream>
int main() {
std::cout << "enter two numbers:" << std::endl;
int v1 = 0, v2 = 0;
std::cin >> v1 >> v2;
std::cout << "the sum of" << v1 << " and " << v2 << "is " << v1 + v2 << std::endl;
std::cout << "the sum of" << v1 << " and " << v2 << "is " << v1 + v2 << "std::endl";
return 0;
}
1.1 输出运算符<<
接受两个对象,ostream对象<<输出的值:将给定的值写入OSTREAM中
std::cout << "enter two numbers:" << std::endl;
//==(std::cout << "enter two numbers:") << std::endl;
//==std::cout << "enter two numbers:";
//== std::cout << std::endl;
打印ENDL,操纵符,效果是,结束当前行,并将与设备关联的缓冲区中的内容都刷到设备中【保证到目前为止产生的所有输出都能真正写入输出流,而不仅·停留在内存中等待写入流】
::作用域运算符
1.2 输入运算符>>
接受两个对象,istream>>对象;从给定的ISTREAM读入数据,并写入右侧中;std::cin>>v1;
std::cin >> v1 >> v2;
//==(std::cin >> v1) >> v2;
//==std::cin>>v1;
//==std::cin>>v2;
1.3 注释
/* */注释界定符不能嵌套
std::cout << "/*";
std::cout << "*/";
std::cout <</*"*/"* / ;
std::cout <</*"*/"/*""/*" * / ;
1.4 控制流
1.4.1 WHILE语句——和C一样咯
#include <iostream>
using namespace std;
int main()
{
int sum = 0, val = 1;
while (val <= 10) {
sum += val;
++val;
}
cout << "sum of 1 to 10 inclusive is"<<sum << endl;
return 0;
}
递增也一样,++A,输出之后的,A++,输出之前的
#include <iostream>
using namespace std;
int main()
{
int sum = 0, val = 1;
while (val <= 10) {
sum += val;
cout << ++val << endl;
//cout << val++ << endl;
}
cout << "sum of 1 to 10 inclusive is"<<sum << endl;
return 0;
}
练习1.9 WHILE50-100整数相加
#include <iostream>
using namespace std;
int main()
{
int sum = 50, val = 51;
while (val <= 100) {
sum += val;
++val ;
}
cout << "sum of 50 to 100 inclusive is "<<sum << endl;
return 0;
}
练习1.10 递减打印10-1
#include <iostream>
using namespace std;
int main()
{
int val = 10;
while (val >=0) {
cout<<val--<<endl ;
}
return 0;
}
练习1.11 指定两个整数之间的所有整数,打印
#include <iostream>//没有比较大小哦,小的在前大的在后
using namespace std;
int main()
{
int val1 ,val2;
cin >> val1 >> val2;
val1 -= 1;
while (val1<val2) {
cout<<val1++<<endl ;
}
/*while (val2 - 1 <= val1) {
cout << val2++ << endl;
}VAL1的值改变了*/
return 0;
}
1.4.2 for语句——和C一样
#include <iostream>
using namespace std;
int main()
{
int sum = 0;
for (int val = 1; val <= 10; ++val)
sum += val;
cout << sum << endl;
return 0;
}
练习1.12 ==0
#include <iostream>
using namespace std;
int main()
{
int sum = 0;
for (int val = -100; val <= 100; ++val)
sum += val;
cout << sum << endl;
return 0;
}
练习1.13 for做9-11
#include <iostream>
using namespace std;
int main()
{
int sum = 0;
for (int val =50; val <= 100; ++val)
sum += val;
cout << sum << endl;
return 0;
}
#include <iostream>
using namespace std;
int main()
{
for (int val = 10; val >= 0; --val)
cout << val << endl;
return 0;
}
#include <iostream>
using namespace std;
int main()
{
int v1, v2;
cin >> v1 >> v2;
for (int val = v1+1; val < v2; ++val)
cout << val << endl;
return 0;
}
今天学点简单的,笑死