Problems encountered in C + + learning __c++

Source: Internet
Author: User

First, #ifndef的作用.

The following files are in "Os_cpu.h".

#ifndef __os_cpu_h__

#define__OS_CPU_H__

/*

There are many definitions in the middle of the statement. ;;

*/

#endif/*__os_cpu_h__*/

In this way, during the compile phase (Ifndef is the function of the compile phase.) The fake two files include this file (Os_cpu.h), and if one of the two files is compiled first, then __os_cpu_h__ is defined. When you compile to the second file, the initial judgment (IFNEF) will automatically jump out of the Os_cpu.h file for repeated compilation. This avoids the repeated compilation of the file.

second, the role of stdafx.h.

Avoid repeating the. cpp file in include

Any. cpp files that you write must first contain stdafx.h.

AppWizard compile stdafx.cpp After build stdafx.pch file, VC after compiling. cpp file read and use the. pch file, no longer compiling windowsinclude files unless you edit the StdAfx file

iii. char** argv, char* argv, Char *argv[] distinction

The value of Char *a:a contains character data, which cancels the reference to a (*a) to get a character,

Do not dereference to get a string, printf ("%c", *a) output a character or printf ("%s", a) output string;

The value of Char **a:a contains an address, the address contains character type data, cancels the reference to a (*a), gets the address, cancels the reference to the address (**a), obtains a character, printf ("%c", **a) outputs a character printf ("%s", *a) Output string;

Char *a[]:a is an array whose element is the address (the address is actually a pointer), the address contains a character data, printf ("%c", *a[i]) outputs a character, printf ("%s", A[i]) output string;

Char *a or char**a can change the value of a, char a*[] cannot change the value of a.

Main (int argc, char*argv[]) {}//No difference

Main (int argc, CHAR**ARGV) {}//No difference

For example, the command line:

Aaa.exe X.dat 5 6

When used in a program, consider argv as a set of string arrays.

ARGC was 4.

Argv[0] is the first position variable in the command line, which is the program name. Aaa.exe

ARGV[1] is the second position variable on the command line, parameter one: X.dat

ARGV[2] is the third position variable on the command line, parameter two: 5

ARGV[3] is the third position variable on the command line, parameter three: 6

Use in the program:

Char namein[80];

int nx,ny;

printf ("Theprog is%s\n", argv[0]); Play executable program name Aaa.exe

strcpy (namein,argv[1])//Enter file name from parameter one get X.dat

SSCANF (Argv[2], "%d", &nx);/NX 5

SSCANF (Argv[3], "%d", &ny);/NY 6

Four, link:fatal error lnk1123:failure duringconversion to coff:file invalid or corruptincremental is what. It has any effect.

Incrementallinking translated into Chinese is "incremental link", is a link to the parameter options, the role is to improve the speed of the link. What does that mean. When you do not use incremental links, each change or add code after the link will be shuffled, the original. exe deleted, relink to a new. exe, so that the link will be slow for large projects. When you choose an incremental link, a small change to the code will insert the new function or data into an existing. exe, without regenerating the. exe, which can be rearranged only if you make a large number of changes, which will increase the speed of the link.

The default setting for general vs is to set the debug version of Incrementallinking to Yes (/incremental) and set the release version to NO (/incremental:no).

Five, C + + input and output

You can use the printf ("") of C; scanf ("");

C + + has its own input and output cin and cout

#include <iostream>

Voidmain ()

{std::cout<< "HelloWorld" <<ENDL;}

}

Or

#include <iostream>

Usingname Space Std;

Voidmain () {

cout<< "HelloWorld" <<endl;

}

Some of the I/O operators are commonly used:

Dec

Formatted as decimal numeric input output

Hex

format as hexadecimal numeric input output

Oct

Format to octal numeric input output

Setiosflags (Long flag)

Sets the flag bit input output specified in the flag

Resetiosflags (Long Flags)

Clears the specified flag bit input output in flag

Ws

Set check-in blank character input in skipped input

SETW (int width)

Sets the width of the output data segment to output

Set precision (int num)

Set floating-point number precision digits output

Setfill (int ch)

Set CH to fill character output

Endl

Output a newline character and refresh the flow output.

Ends

Output a null character ' \ n ' to end string output

Flush

System Refresh Flow Output

Related Article

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.