C + + language learning--LRJ Getting started classic notes

Source: Internet
Author: User

1.SCANF input format, Space, tab, and carriage return are irrelevant, so pressing the ENTER key does not mean that the input ends.

Tell the program how to enter the end:

Under Windows, press ENTER when you are finished, press CTRL + Z, and then press ENTER.

Under Linux, press Ctrl+d when you are finished typing

2.GCC compilation options

-wall pointed out the warning

-ansi judging whether and ANSI conflicts

-pedantic more stringent than ANSI

-LM Link Math Library, C + + compiler will automatically link

-ddebug compile-time definition symbol debug, can be replaced by other, such as-dlocal will define the symbol local

3. Two ways to use file input and output: Redirect and fopen:

redirect example:

Freopen ("data.in","R", stdin); Freopen (" Data.out ","w", stdout);

fopen Example:

#include <stdio.h>FILE*fin, *Fout;fin= fopen ("data.in","RB"); Fout= fopen ("Data.out","WB"); fscanf (FIN,"%d", &x); fprintf (Fout,"%d", x); fclose (Fin); fclose (Fout) ;

4. Use printf and scanf input output long Long is a unified use of%LLD in Linux, and MinGW gcc and VC6 in Windows need%i64d, but VS2008 uses%LLD

5. You can use a in the # define a B program to replace all B

6. Larger arrays should be declared outside of the main function as much as possible

7. Use FGETC (FIN) to read a character from the open file fin. In general, you should check that it is not EOF and then converted to a char value.

Take one character from the standard input output with GetChar, equivalent to fgetc (stdin);

8.fgets (buf, MAXN, Fin) The full line of reading is placed in the character array buf, and it should be ensured that the BUF is sufficient to store a line of the file. BUF always ends with ' \ n ' except when the file ends without encountering the ' \ n ' special case. When a character is not read, fgets returns NULL.

Fgets is more secure and MAXN limited than get.

getline:istream& getline (IStream &is, String &str, Char Delim)

istream& getline (IStream &is, string &str) This situation Delim for line wrapping

Getline reads the Delim and discards it.

For example Getline (CIN, name, ' \ n ');

istream::getline:istream& getline (char *s, streamsize N) This situation Delim for line wrapping

istream& getline (char *s, streamsize N, Char Delim)

For example Cin.getline (s,100, ' \ n ');

9. Tools such as Isalpha,isdigit,isprint defined in header file Ctype.h can be used to determine character properties, while tools such as ToUpper, ToLower, and so on can be used to convert case.

The content returned by 10.STRING.C_STR () is read-only.

11. Use the Assert macro in assert.h to restrict illegal function calls

ASSERT (x>0);

The code terminates abnormally when x≤0.

12.gdb prints all the stack frame information with the BT (backtrace) command, and the UP command selects the previous stack frame.

C + + language learning--LRJ Getting started classic notes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.