2 ¶
, 개 ¶
- : 감 구
- (loop invariant): while 그 경 고 . 걸 고, 개 고 각. 고 , while while 과 간 .( 기 ...) 계기 . , , .
~cpp
//: 금까 r개
int r=0;
//r 0
while(r!=rows)
{
//기 고
// 거 ( )
std::cout<<std::endl;
//r
++r;
}
//기 고
- (short-circuit): 그까 if(a==0||b==0){...} a==0 b==0 고 . ||기 |기 구 . , .
- : , a+=b, a=a+b .
- 개: , for(i=0;i<3;i++)처럼, 시작인 0은 포함하나 3은 포함하지 않고 2에서 끝난다. 이것을 [0,3)으로 표현하는데, 3은 루프 범위에 표현되지 않는 "끝을 벗어난 값"이다.
string ¶
- 1 string . SeeAlso Yggdrasil//1
~cpp std::string::size_type//unsigned , 갯 . type .
- 1 0
- 그 "그 1 0 " , 계 그까 그게 .
- (개) , [0,5) 5 게 . 1,5 5 기 .
- 기 .
- 그 "그 1 0 " , 계 그까 그게 .
2-1 ¶
- pad 0 기 .
2-2 ¶
- pad , 각각 . , rows, cols 기 .
2-3 ¶
~cpp
#include<iostream>
#include<string>
using std::cin;
using std::cout;
using std::endl;
using std::string;
int main()
{
int pad_rows, pad_cols;
cout<<"Please input blank of rows and cols:";
cin>>pad_rows;
cin>>pad_cols;
cout<<"Please enter your first name: ";
string name;
cin>>name;
const string greeting="Hello, "+name+"!";
const int rows=pad_rows*2+3;
const string::size_type cols=greeting.size()+pad_cols*2+2;
cout<<endl;
for(int r=0;r!=rows;++r)
{
string::size_type c=0;
while(c!=cols)
{
if(r==pad_rows+1&&c==pad_cols+1)
{
cout<<greeting;
c+=greeting.size();
}
else
{
if(r==0||r==rows-1||c==0||c==cols-1)
cout<<"*";
else
cout<<" ";
++c;
}
}
cout<<endl;
}
return 0;
}
2-6 ¶
- 1 10 각 .
2-7 ¶
- for(int i=10;i>-6;i--) std::cout<
2-8 ¶
~cpp
#include<iostream>
#include<string>
int main()
{
int sum=1;
for(int i=1;i<10;i++)
sum*=i;
std::cout<<sum;
return 0;
}










