c++ programming - 1st study

16

Upload: -

Post on 20-Jul-2015

2.805 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: C++ Programming - 1st Study
Page 2: C++ Programming - 1st Study
Page 3: C++ Programming - 1st Study

3

Page 4: C++ Programming - 1st Study

#include <stdio.h>

int main(){

printf("Hello, World!");

return 0;}

#include <iostream>

int main(){

std::cout << "Hello, World";

return 0;}

C C++

4

Page 5: C++ Programming - 1st Study

#include <stdio.h>

int main(){

int x = 10, y = 20;

printf("x = %d, y = %d\n", x, y);

return 0;}

#include <iostream>

int main(){

int x = 10, y = 20;

std::cout << "x = " << x<< ", y = " << y << std::endl;

return 0;}

C C++

5

Page 6: C++ Programming - 1st Study

#include <stdio.h>

int main(){

int x = 0;

printf("Input the number: ");scanf("%d", &x);

printf("x = %d\n", x);

return 0;}

#include <iostream>

int main(){

int x = 0;

std::cout << "Input the number:";std::cin >> x;

std::cout << "x = " << x<< std::endl;

return 0;}

C C++

6

Page 7: C++ Programming - 1st Study
Page 8: C++ Programming - 1st Study

8

Page 9: C++ Programming - 1st Study

#include <stdio.h>

int main(){

int i = 1;

if (i)printf("i is true!\n");

elseprintf("i is false!\n");

return 0;}

#include <iostream>

int main(){

bool b = true;

if (b)std::cout << "b is true!"

<< std::endl;else

std::cout << "b is false!"<< std::endl;

return 0;}

C C++

9

Page 10: C++ Programming - 1st Study

#include <iostream>

int main(){

bool b = true;

std::cout << b << std::endl;std::cout << !b << std::endl;

return 0;}

10

Page 11: C++ Programming - 1st Study

#include <iostream>

int main(){

bool b = true;

std::cout.setf(std::ios::boolalpha);std::cout << b << std::endl;std::cout << !b << std::endl;

std::cout.unsetf(std::ios::boolalpha);std::cout << b << std::endl;std::cout << !b << std::endl;

return 0;}

11

Page 12: C++ Programming - 1st Study
Page 13: C++ Programming - 1st Study

13

Page 14: C++ Programming - 1st Study

#include <iostream>

int main(){

int i1 = 10;double d1 = 3.14;

return 0;}

#include <iostream>

int main(){

auto i2 = 10;auto d2 = 3.14;

return 0;}

C++98 C++11

14

Page 15: C++ Programming - 1st Study

#include <iostream>#include <vector>#include <string>#include <tuple>

int main(){

std::vector<std::tuple<std::string, int, double>> vStudents;

for (std::vector<std::tuple<std::string, int, double>>::iterator iter =vStudents.begin(); iter != vStudents.end(); ++iter) { … }

return 0;}

C++98

15

Page 16: C++ Programming - 1st Study

#include <iostream>#include <vector>#include <string>#include <tuple>

int main(){

std::vector<std::tuple<std::string, int, double>> vStudents;

for (auto iter = vStudents.begin(); iter != vStudents.end(); ++iter) { … }

return 0;}

C++11

16