WSU logo


College of Engineering & CS
Wright State University
Dayton, Ohio 45435-0001

CEG 333: Introduction to Unix

Prabhaker Mateti

Emacs: C++ Mode


CC Mode is collection of Emacs modes for editing source code in C-related languages, including C++ and Java. It integrates many special features into Emacs for these languages, such as:

Emacs will automatically open .cpp files in C++ Mode. The modeline displays the text "C++" to reflect this.

Some example C++ code (which outputs all its command line arguments, in order) as colorized by Emacs:

      #include <cstdio>

      int main(int argc, char *argv[]) {
          for (int i = 0; i < argc; i++) {
	      std::printf("arg %i: %s\n", i, argv[i]);
          }


	  return 0;
      }
    

Emacs can also integrate compilation and debugging of programs. Typing M-x compile can run make, g++, or any other such command. Emacs will then automatically parse the output of this command.

If any errors or warnings are encountered during compilation, Emacs allows the user to view them in the compilation buffer and automatically jump to problem lines in the original file (using M-x next-error, M-x previous-error, and M-x first-error).