C++	  -­‐	  for	  Java	  Developers:	                 Intro	  to	  C++	              Jussi	  Pohjolainen	  Tampere	  Unive...
C++	  •  1998	  ANSI/ISO	  Standard:	      –  Core	  language	      –  Standard	  Library	  •  Many	  C++	  libraries	  ex...
C++	  Standard	  Library	  •  Containers	      –  array,	  bitset,	  deque,	  forward_list,	  list,	  …	  vector	  •  Gene...
C	  Standard	  Library	  •  Macros,	  typedefiniUons,	  funcUons	  for	  tasks	     like	  string	  handling,	  mathemaUcal...
Diagram	  from:	  hYp://faculty.cs.niu.edu/~mcmahon/CS241/Notes/compile.html	  
GCC	  Compiler	  •  The	  GNU	  Compiler	  CollecUon	  (GCC)	  is	  a	     compiler	  system	  produced	  by	  the	  GNU	 ...
Installing	  •  Ubuntu	      –  sudo	  apt-­‐get	  install	  g++	  •  Mac	  OS	  X	      –  Install	  Xcode	  and	  instal...
Compiling	  C++	  Program	  •  Simple	     –  g++ mysourcecode.cpp•  BeYer	     –  g++ -ansi -pedantic -wall      mysource...
Code	  Style	  •  Java	  has	  “standard”	  for	  code	  style,	  C++	  does	     not.	  •  Use	  can	  use	  separate	  a...
Makefiles	  •  All	  these	  command	  line	  arguments	  can	  be	     long	  and	  hard	  to	  write.	  •  Use	  Make!	  ...
makefile
WHAT	  ABOUT	  QT?	  
Qt	  Hello	  World	  #include <QApplication>#include <QPushButton>int main(int argc, char *argv[]){    QApplication app(ar...
SOME	  C++	  SYNTAX	  
cout	  for	  output,	  cin	  for	  input	  •  Output	      –  cout	  <<	  “hello!”;	  •  Input	      –  cin	  >>	  someVar...
Datatypes	  •  Fundamental	  types	      –  int,	  short,	  long	      –  float,	  double,	  long	  double	      –  bool	  ...
const	  and	  enum	  // Like final in Javaconst int NUMBER = 100;// Using enumsenum DAY { MON = 1, TUE, WED, THU, FRI,SAT,...
CondiUons	  in	  C++	  int a = 0;if(a = 0){   cout << “What the..” << endl;}
Arrays	  const int LENGTH = 5;int numbers[LENGTH];numbers[0] = 12;numbers[1] = 88;..
About	  Strings	  •  C++	  has	  two	  kind	  of	  Strings	      –  char	  arrays	      –  string	  –	  class	  
C	  type	  strings	  •  char	  myString[6]	  =	  “Jussi”;	  •  //	  Why	  6??	  The	  array	  contains	  now	  Jussi0!	  •...
cin.get	  // Reads maxLength number of chars// from the usercin.get(myString, maxLength);// This leaves user given enter ‘...
Intro to C++ - language
Intro to C++ - language
Intro to C++ - language
Intro to C++ - language
Intro to C++ - language
Intro to C++ - language
Intro to C++ - language
Upcoming SlideShare
Loading in …5
×

Intro to C++ - language

9,614 views

Published on

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
9,614
On SlideShare
0
From Embeds
0
Number of Embeds
33
Actions
Shares
0
Downloads
341
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Intro to C++ - language

  1. 1. C++  -­‐  for  Java  Developers:   Intro  to  C++   Jussi  Pohjolainen  Tampere  University  of  Applied  Sciences  
  2. 2. C++  •  1998  ANSI/ISO  Standard:   –  Core  language   –  Standard  Library  •  Many  C++  libraries  exist  that  are  not  part  of   the  standard    •  New  standard:  ISO/IEC:2011  C++11  
  3. 3. C++  Standard  Library  •  Containers   –  array,  bitset,  deque,  forward_list,  list,  …  vector  •  General   –  algorithm,  funcUonal,  iterator,  locale,  memory…  •  Strings   –  string  •  Input  and  Output   –  ios,  iostream,  ostream,  sstream..  •  Numerics   –  complex,numeric,  valarray  •  Language  support   –  excepUon,  limits,  new,  typeinfo  
  4. 4. C  Standard  Library  •  Macros,  typedefiniUons,  funcUons  for  tasks   like  string  handling,  mathemaUcal   computaUons,  memory  allocaUons..  •  See:   –  hYp://en.wikipedia.org/wiki/C_standard_library  
  5. 5. Diagram  from:  hYp://faculty.cs.niu.edu/~mcmahon/CS241/Notes/compile.html  
  6. 6. GCC  Compiler  •  The  GNU  Compiler  CollecUon  (GCC)  is  a   compiler  system  produced  by  the  GNU  Project   supporUng  various  programming  languages.  •  C  (gcc),  C++  (g++),  ObjecUve-­‐C  (gobjc),  Fortran   (gfortran),  Java  (gcj)  •  CompaUble  IDEs   –  Dev-­‐C++  (Win),  NetBeans,  Eclipse,  QtCreator,   Xcode  
  7. 7. Installing  •  Ubuntu   –  sudo  apt-­‐get  install  g++  •  Mac  OS  X   –  Install  Xcode  and  install  command  line  tools  •  Windows   –  For  example  minGW:  hYp://sourceforge.net/ projects/mingw/  
  8. 8. Compiling  C++  Program  •  Simple   –  g++ mysourcecode.cpp•  BeYer   –  g++ -ansi -pedantic -wall mysourcecode.cpp -o myapp•  Running   –  ./myapp
  9. 9. Code  Style  •  Java  has  “standard”  for  code  style,  C++  does   not.  •  Use  can  use  separate  apps  for  “preffy”  your   source  code  •  For  example:  ArUsUc  Style   –  hYp://astyle.sourceforge.net/  
  10. 10. Makefiles  •  All  these  command  line  arguments  can  be   long  and  hard  to  write.  •  Use  Make!  UUlity  that  automaUcally  builds   apps.  •  hYp://en.wikipedia.org/wiki/Make_(sohware)  
  11. 11. makefile
  12. 12. WHAT  ABOUT  QT?  
  13. 13. Qt  Hello  World  #include <QApplication>#include <QPushButton>int main(int argc, char *argv[]){ QApplication app(argc, argv); QPushButton hello("Hello world!"); hello.resize(100, 30); hello.show(); return app.exec();}
  14. 14. SOME  C++  SYNTAX  
  15. 15. cout  for  output,  cin  for  input  •  Output   –  cout  <<  “hello!”;  •  Input   –  cin  >>  someVariable;  
  16. 16. Datatypes  •  Fundamental  types   –  int,  short,  long   –  float,  double,  long  double   –  bool   –  char  •  Derived  types   –  arrays,  pointers,  references..  •  Class  types   –  class,  struct,  union  
  17. 17. const  and  enum  // Like final in Javaconst int NUMBER = 100;// Using enumsenum DAY { MON = 1, TUE, WED, THU, FRI,SAT, SUN };DAY today = MON;
  18. 18. CondiUons  in  C++  int a = 0;if(a = 0){ cout << “What the..” << endl;}
  19. 19. Arrays  const int LENGTH = 5;int numbers[LENGTH];numbers[0] = 12;numbers[1] = 88;..
  20. 20. About  Strings  •  C++  has  two  kind  of  Strings   –  char  arrays   –  string  –  class  
  21. 21. C  type  strings  •  char  myString[6]  =  “Jussi”;  •  //  Why  6??  The  array  contains  now  Jussi0!  •  char  myString[]  =  “Jussi”  
  22. 22. cin.get  // Reads maxLength number of chars// from the usercin.get(myString, maxLength);// This leaves user given enter ‘n’ to input// stream, use cin.get again to get rid of//it..

×