`
sai_ruby
  • 浏览: 22778 次
  • 性别: Icon_minigender_2
  • 来自: 北京
社区版块
存档分类
最新评论

C++笔记(1)

 
阅读更多
stringstream allows a string-based object to be treated as a stream. This way we can perform extraction or insertion operationgs from/to strings, which is especially useful to convert strings to numerical values and vice versa.
e.g.
string mystr("1024");
int myint;
stringstream(mystr)>>myint;

Using this method, instead of direct extractions of integer values, we have more control over what happens with the input of numeric values from the user, since we are separating the process of obtaining input from the user (we now simply ask for lines) with the interpretation of that input. Therefore, this method is usually preferred to get numerical values from the user in all programs that are intensive in user input.

翻译一下大概意思就是:把用户输入与输入内容的解析分离,有利于对输入的控制。

exit is a function defined in the cstdlib library.
The purpose of exit is to terminate the current program with a specific exit code. Its prototype is:
void exit (int exitcode);
The exitcode is used by some operating systems and may be used by calling programs. By convention, an exit code of 0 means that the program finished normally and any other value means that some error or unexpected results happened.

Passing by reference is also an effective way to allow a function to return more than one value.

When declaring a function we can specify a default value for each of the last parameters.If a value for that parameter is not passed when the function is called, the default value is used, but if a value is specified this default value is ignored and the passed value is used instead.

Notice that a function cannot be overloaded only by its return type. At least one of its parameters must have a different type.

inline function
The inline specifier indicates the compiler that inline substitution is preferred to the usual function call mechanism for a specific function. This does not change the behavior of a function itself, but is used to suggest to the compiler that the code generated by the function body is inserted at each point the function is called, instead of being inserted only once and perform a regular call to it, which generally involves some additional overhead in running time.
内联函数的执行效率比一般函数调用效率高。

char myword [] = { 'H', 'e', 'l', 'l', 'o', '\0' };
char myword [] = "hello";
In both cases the array of characters myword is declared with a size of 6 elements of type char: the 5 characters that compose the word "Hello" plus a final null character ('\0') which specifies the end of the sequence and that,in the second case, when using double quotes (") it is appended automatically.
notice that we are talking about initializing an array of characters in the moment it is being declared, and not about assigning values to them once they have already been declared. In fact because this type of null-terminated arrays of characters are regular arrays we have the same restrictions that we have with any other array, so we are not able to copy blocks of data with an assignment operation

& is the reference operator and can be read as "address of"
* is the dereference operator and can be read as "value pointed by"

an array is just like a constant pointer

To conduct arithmetical operations on pointers is a little different than to  conduct them on regular integer data types. To begin with, only addition and subtraction operations are allowed to be conducted with them, the others
make no sense in the world of pointers. But both addition and subtraction have a different behavior with pointers according to the size of the data type to which they point.

void pointers
This allows void pointers to point to any data type, from an integer value or a float to a string of characters. But in exchange they have a great limitation: the data pointed by them cannot be directly dereferenced (which is logical, since we have no type to dereference to), and for that reason we will always have to cast the address in the void pointer to some other pointer type that points to a concrete data type before dereferencing it.

C++ allows operations with pointers to functions. The typical use of this is for passing a function as an argument to another function, since these cannot be passed dereferenced.

*p++ = *q++;
Because ++ has a higher precedence than *, both p and q are increased, but because both increase operators (++) are used as postfix and not prefix, the value ssigned to *p is *q before both p and q are increased. And then both are increased. It would be roughly equivalent to:
*p = *q;
++p;
++q;
分享到:
评论

相关推荐

    effective c++笔记1

    Effective C++笔记1 本笔记总结了Effective C++的第1到第11条款,涵盖了C++语言的多个方面,包括构造函数、拷贝构造函数、拷贝赋值函数、const关键字、enum、inline函数、定义域、static变量、初始化、编译器生成的...

    Effective C++笔记1

    Effective C++笔记1 本笔记概括了 Effective C++ 中的四十个规则的第一个部分,涵盖了 C++ 语言的基本概念、const 的使用、inline 函数的应用、对象的初始化等方面。 规则 1:将 C++ 视为语言联合体 -------------...

    千锋C++笔记.zip

    《千锋C++笔记》是一份综合性的学习资料,涵盖了C++编程语言的基础到高级概念。这份笔记由知名教育机构“千锋”提供,旨在帮助初学者和有一定基础的程序员深入理解和掌握C++这一强大的系统级编程语言。下面将详细...

    C++学习笔记本

    C++学习笔记C++学习笔记C++学习笔记C++学习笔记C++学习笔记

    c++学习笔记精华版

    ### C++ 学习笔记精华版 #### 一、C++ 语言概述 **1、历史背景** - **C++ 的江湖地位** - Java、C、C++、Python、C# 是当前主流的编程语言之一,而 C++ 在这些语言中以其高效性和灵活性著称。 - **C++ 之父 ...

    C++笔记.rar C++笔记.rar

    这份"C++笔记"包含了学习C++时的重要知识点和实践技巧。 1. **基础语法**:C++的基础包括变量、数据类型(如整型、浮点型、字符型等)、运算符(算术、比较、逻辑、位运算符等)、流程控制语句(如if-else、switch-...

    C++笔记.md

    C++笔记.md

    自考C++笔记(上)

    "自考C++笔记(上)" 本笔记是作者全部手打创作的自考C++笔记,包含课本中例子的详细分析,共47200字,适合没有学过C语言的人认真学习和通过C++自考。 C++程序设计 ### 认识 C++的对象 #### 1.1 初识 ...

    C++学习笔记.pdf

    C++学习笔记

    C++笔记(1).md

    C++笔记(1).md

    C++核心学习笔记pdf

    C++核心学习笔记pdf

    某课网C++笔记pdf

    根据给定的信息,我们可以从多个角度来探讨C++的相关知识点,包括但不限于集成开发环境的配置、数据类型初始化、命名空间的使用、类和对象的概念、引用类型的理解、指针的操作、函数重载以及内存管理等方面。...

    大一下c++笔记.md

    大一下c++笔记.md

    钱能的C++笔记,绝对值的珍藏.rar

    在C++备课笔记1中,钱能可能涵盖了C++的基础语法,比如变量声明、数据类型、控制结构(如if语句、for循环、while循环)、函数的定义和调用,以及指针的基本操作。这些都是C++初学者必须掌握的基础知识,也是进一步...

    c++学习笔记.pdf

    1. 关于C和C++语言的互调问题,extern "C"的作用至关重要。它确保了C++代码能够调用C语言编写的函数,而不会产生因为语言规范差异导致的编译错误。C++编译器在处理函数声明时会考虑函数签名(包括参数类型),而C...

    c++笔记个人整理

    ### C++核心知识点详解 #### 内联函数与宏比较 内联函数是C++中一种特殊的函数,它能够在函数调用处被编译器直接替换为函数体,从而避免了函数调用的开销。这与宏有些相似,但内联函数保留了函数的所有特性,如...

    达内C/C++笔记

    C++笔记可能涵盖了C++的更多高级特性,如模板元编程、STL的深度使用、设计模式、多线程编程、Boost库的运用等。这些内容可以帮助开发者写出更加高效、可维护的代码。 1. **模板元编程**:在编译时进行计算,减少...

    C++笔记初学者的期末老师

    总的来说,C++笔记对于初学者来说是一份宝贵的学习资料,它涵盖了C++的基础知识,如程序结构、面向对象特性、函数的使用等,这些都是学习C++必备的基础。通过深入理解和实践这些概念,初学者可以逐步掌握C++编程,并...

    c++笔记.txt

    根据提供的文件信息,可以看出这份文档主要涉及C++中的一些关键概念和知识点,特别是关于静态成员、友元类、以及常量等内容。接下来,我们将详细解释这些知识点。 ### 静态成员 静态成员(包括静态数据成员和静态...

Global site tag (gtag.js) - Google Analytics