C++ NOTES: QUICK REFERENCE

  1. Books
  2. Compiler Issues
  3. BASICS of LANGUAGE
  4. FAQs
  5. SPECIAL TOPICS
GO TO BOTTOM


  1. BOOKS:
  2. INTERACTION WITH COMPILER:
  3. COMMENTS:
  4. Boolean expressions,
  5. BigNumber package (for g++, not CC): include the Integer.h file. E.g.
  6. Delete: E.g. delete Iptr; // deletes a single variable But if Iptr points to a dynamically allocated array, the symbol [] must be inserted: delete [] Iptr; NOTE: be sure to ONLY use pointers with "delete" that were previously used with "new". (From Gaddis book, p.553) NOTE: if destructors (e.g. ~Polynomial) is wrongly done, you can get mysterious errors and core dumps at the END of the program! This is because the destructors are called at the programs
  7. MANUAL pages.
  8. Random Numbers
  9. Ellipsis See p.134 of Stroustrup for working with ellipsis: Need to include < stdarg.h >. E.g. (in my design for integer expression package)
    	Integer Expr::ExprEval(const Expr & e, ErrBd relErr, ErrBd absErr ...)
    	{
    	 va_list ap;
    	 Param x;
    	 Integer n;
    	 // set up the arguments for evaluation
    	 va_start(ap,absErr);	// arg startup
    	 for (;;) {
    		x = va_arg(ap,Param);
    		if (x==0) break;
    		n = va_arg(ap,Integer);
    		if (n==0) break;
    		x.Assign(n);
    	 }
    	 va_end(ap);
    	}
    	


    SPECIAL TOPICS

  10. Timing tests: see the file "timing.cc", modified from Glauner.
  11. Command line arguments and main():
  12. STL:
  13. Threads: do "man thr_create".
  14. TCP/IP: do "man tcp".
  15. Limits (max float, min integer, etc): See the file: /usr/include/limits.h You can include these definitions using #include < limits.h >
  16. Standard Libraries
    	#include < stdlib.h >	-- when to use this?
    	#include < iostream.h >	
    	
  17. Strings If you need to get the char* inside a std::string, use its "data()" function:
    		std::string s = "abc";
    		char * c = s.data();
    	
  18. Templates If you have static members inside a template class, you need to declare it outside the class before use:
    	template 
    	 Poly {
    	  static int my_static;   // for int, you could initialize it here!
    	  ...
     	 }
    
    	template
    	  int Poly::my_static = 3;
    	
    More on templates, from http://www.cplusplus.com/doc/tutorial/templates/.

  19. Streams To use input/output file Streams,
    	#include 
    
    	std::ifstream ifs("inputfile");
    
    	std::ofstream ofs;
    	ofs.open("outputfile");		// if s is a string, then
    					// use ofs.open(s.data());
    	ofs.close();			// graceful exit
    	...
    	

    GO TO TOP Please send comments to yap at cs dot nyu dot edu.