반응형
- Simple comsole output
#include <iostream>
using namespace std;
int main()
{
cout << "Welcome to C++!" << endl;
return 0;
}
-> #include : compiler preprocessor directive [컴파일러 전처리 지시자]
-> iostream : standard input output header file
-> cout : is same printf of C
- cout and << operator
- cout
- console output
- standard C++ output stream object
- << operator
- stream insertion operator
- multiple object value operator [C와는 다른점]
- cout
- cin, cout defined in iostream header
- namespace [이름공간]
- Name(identifier) conflicts
- namespace keyword
- name conflict resolution [이름충돌 해결]
- Names declared in a namespace are separate from other namespaces
- using name space std;
- cout and cin are defined in the iostream library in the std namespace
- std::
- one of the namespeaces defined by the ANSI C++ standard
- std:: prefix [접두사]
- std::cout, std::cin, std::endl
- can omit std::
- "using namespace std"ons
- computing with numbers
- mathematical computations and displays the result to the console
#include <iostream>
using namespace std;
int main()
{
cout << "(10.5+2*3) / (45-3.5)=";
cout << (10.5 + 2 * 3) / (45 - 3.5) << endl;
return 0;
}
- Programming Errors
- syntax errors
- Missing braces : { }
- Missing Semicolons : ;
- Missing Quotation Marks : " "
- Misspelling Names : Name conflicts
- runtime errors
- impossible syntax like division '0'
- logic errors
- loop forever [condition not set]
- syntax errors
#include <iostream>
using namespace std;
//prototype of area
double area(int r);
int main_intheclass()
{
int n = 3;
//cout the return value from area () which calculates area of a circle
cout << area(n);
char c = '#';
cout << c << 5.5 << '-' << n << "hello" << endl;
cout << "n + 5 = " << n + 5 << endl;
return 0; // OS로 보낸다
}
double area(int r)
{
double ret = 3.14159 * r * r; //double r로 지정하면 안된다.
return ret; // return r로 하면 안된다.
}
반응형
'Programming > C++ 1' 카테고리의 다른 글
[C++] Swap Function (0) | 2021.04.04 |
---|---|
[C++] Chapater 7. Single-Dimensional Arrays and C-Strings (0) | 2021.04.04 |
[C++] Chapter 6. Functions (0) | 2021.04.04 |
[C++] Chapter 2. Elementary Programming (0) | 2021.04.04 |
C++ 공부하기 1 (0) | 2021.03.27 |