Intro to C++ - language
Upcoming SlideShare
Loading in...5
×
 

Intro to C++ - language

on

  • 2,125 views

 

Statistics

Views

Total Views
2,125
Views on SlideShare
2,125
Embed Views
0

Actions

Likes
0
Downloads
37
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Intro to C++ - language Intro to C++ - language Presentation Transcript

  • C++  -­‐  for  Java  Developers:   Intro  to  C++   Jussi  Pohjolainen  Tampere  University  of  Applied  Sciences  
  • 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  
  • 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  
  • C  Standard  Library  •  Macros,  typedefiniUons,  funcUons  for  tasks   like  string  handling,  mathemaUcal   computaUons,  memory  allocaUons..  •  See:   –  hYp://en.wikipedia.org/wiki/C_standard_library  
  • 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  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  
  • 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/  
  • Compiling  C++  Program  •  Simple   –  g++ mysourcecode.cpp•  BeYer   –  g++ -ansi -pedantic -wall mysourcecode.cpp -o myapp•  Running   –  ./myapp
  • 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/  
  • 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)  
  • makefile
  • WHAT  ABOUT  QT?  
  • 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();}
  • SOME  C++  SYNTAX  
  • cout  for  output,  cin  for  input  •  Output   –  cout  <<  “hello!”;  •  Input   –  cin  >>  someVariable;  
  • Datatypes  •  Fundamental  types   –  int,  short,  long   –  float,  double,  long  double   –  bool   –  char  •  Derived  types   –  arrays,  pointers,  references..  •  Class  types   –  class,  struct,  union  
  • const  and  enum  // Like final in Javaconst int NUMBER = 100;// Using enumsenum DAY { MON = 1, TUE, WED, THU, FRI,SAT, SUN };DAY today = MON;
  • 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!  •  char  myString[]  =  “Jussi”  
  • 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..