“There is not love of life without despair about life.”
——Albert Camus
Preface
After concluding a part of my vacation, I've started intermittently writing some notes about C++. These notes could vary in length, mainly focusing on supplementary and comprehensive content beyond my foundational understanding of C++. The aim is to expand knowledge rather than to ascend to higher levels. Hence, I've chosen "C++ Primer" as my first step in learning the C++ language. Firstly, "C++ Primer" holds an unshakable position in the realm of C/C++ languages. Secondly, it presents a certain level of difficulty, making it worth my effort and dedication to delve deeply into learning. In the upcoming blog posts, I will strive to tackle lesser-known and challenging aspects, with less emphasis on the simpler parts.
I sincerely hope to acquire knowledge throughout this learning journey, whether it benefits me personally or the readers.
Chapter One
1. Compiling from the Command Line with Compiler in Page 3:
If we are using a command-line interface, it's common to compile programs within a console window (such as a shell prompt window in UNIX systems or a command prompt window in Windows systems). Assuming our main program is saved in a file named "prog1.cc," we can compile it using the following command:
$ CC prog1.cc
Here, "CC" is the name of the compiler program, and "$" represents the system prompt. The compiler generates an executable file. In Windows systems, this executable file might be named "progl.exe." UNIX systems' compilers usually name the executable file "a.out." To run an executable file on a Windows system, we need to provide the executable file's name, ignoring the ".exe" extension:
$ prog1
In some systems, even if the file is in the current directory, you might need to explicitly specify the file's location. In this case, you can type:
$ .\prog1
The "." followed by a backslash indicates that the file is in the current directory.To run an executable file on a UNIX system, you need to use the full filename, including the file extension:
$ a.out
If you need to specify the file's location, use a "." followed by a forward slash to indicate that the executable file is in the current directory:
$ ./a.out
Accessing the return value of "main" depends on the system. In both UNIX and Windows systems, after executing a program, you can obtain its return value using the "echo" command. In UNIX systems, use the following command to get the status:
$ echo $?
To view the status in Windows systems, enter:
$ echo %ERRORLEVEL%
2.Notes on Comments in Page 8:
Comment delimiters in the form of /* mark the beginning and */ mark the end of comments. Consequently, comments cannot be nested within each other. Compiler errors related to these issues might be challenging to understand and confusing. For example, compiling the following code on your system would result in an error:
/* *Comments within /* */ cannot be nested. *The words "cannot be nested" would be considered source code, *treated like the rest of the program */ int main() { return 0; }
During debugging, it's common to comment out sections of code. As these sections might include comment delimiters, it's best to use single-line comments to comment out each line of the code segment.
// /* // * Anything within a single-line comment will be ignored // * Nested comment delimiters within single-line comments are also ignored // */
3.To end a file using the keyboard in Page 14:
When inputting data from the keyboard into a program, different operating systems have varying conventions for indicating the end of the file. In Windows systems, the input file is ended by typing Ctrl+Z (holding down the Ctrl key while pressing Z) and then pressing Enter or Return. In UNIX systems, including Mac OS X, the file's end is indicated by Ctrl+D.
2023.8.22
NHG :)
文章评论