My simple note on C++

May 30 - 2009 7:44 PM
I want:

  • simple text editor (done in 2016.06 with my universal_tool_template.py)
  • cmd to compile my code without GUI (done in 2017.01 with Qt lib and C++ compiler)
  • run the cmd tool on my mac,win and linux (done in 2016.06 with my universal_tool_template.py)

the solution I found

  1. write a standard c++ main code (on mac)
  2. “g++ main.cpp -o main” using gcc (bundled with Xcode)
  3. I got my “main” binary file, and I “open main” in console (mac),
  4. works
  5. then cross-compile on mac, get win and linux binary

C++ as cross-compile language

  • because standard c++ library is small, you need to write a lot of basic functions
  • 3rd party framework and library are often used to speed up development process
  • VC++ is standard c++ with MFC library (win only) and .NET framework
  • .Net's CLR library also extend c++; (CLI), but it works better with C#, VB.NET and other .NET languages
  • The Common Language Runtime (CLR) is a core component of Microsoft's .NET initiative
  • gcc is “the” best compiler for standard c++ code.
  • Microsoft Visual Studio Visual C++ compiler can compile standard c++ code, and surely can compile the c++ code using MFC and .Net functions, which other compilers can not use.
  • Learning VC++ is actually learning how to use MS Visual Studio IDE and MFC; and you are selling yourself to Microsoft and losing the freedom of going for other Operating Systems other than Windows.
  • However, MS Visual Studio including VC++ is “the” best GUI application development IDE available, and fits Windows best.
  • Mono project is a project porting .Net framework to other platforms, and it is free.

C++ syntax quick guide

  • string and char array operation
    • compare of c++ and c for string operation
      for C++ strings:
       
      string input, other = "\\Someplace\\Data\\file.dat", result;
      cin >> input;
      result = input+other;
       
      for C strings:
       
      char *input= new char[/*here the maximum length for the input string*/], *other="\\Someplace\\Data\\file.dat", *result;
      cin >> input;
      result = new char[strlen(input)+strlen(other)];
      sprintf(result,"%s%s",input,other);

Tutorials