cout

C++Primer第五版 6.1节练习

廉价感情. 提交于 2020-01-16 20:51:38
练习6.1;实参和形参的区别是什么? 通俗解释: 实参是形参的初始值。编译器能以任意可行的顺序对实参求值。实参的类型必须与对应的形参类型匹配。 详解1) 形参变量只有在函数被调用时才会分配内存,调用结束后,立刻释放内存,所以形参变量只有在函数内部有效,不能在函数外部使用。 2) 实参可以是常量、变量、表达式、函数等,无论实参是何种类型的数据,在进行函数调用时,它们都必须有确定的值,以便把这些值传送给形参,所以应该提前用赋值、输入等办法使实参获得确定值。 3) 实参和形参在数量上、类型上、顺序上必须严格一致,否则会发生“类型不匹配”的错误。当然,如果能够进行自动类型转换,或者进行了强制类型转换,那么实参类型也可以不同于形参类型。 4) 函数调用中发生的数据传递是单向的,只能把实参的值传递给形参,而不能把形参的值反向地传递给实参;换句话说,一旦完成数据的传递,实参和形参就再也没有瓜葛了,所以,在函数调用过程中,形参的值发生改变并不会影响实参。 练习6.2:请指出下列函数哪个有错误,为什么?应该如何修改这些错误呢? (a)int f() { string s; //… return s; } (b) f2(int i){/*…*/} (c) int calc(int v1, int v2) /*…*/ } (d) double square(double x) return x*x;  

C++ 11 array

为君一笑 提交于 2020-01-16 04:45:16
Array 是一种大小固定的顺序容器。array 的申明: template <class T, size_t N> class array; Array内部只存储所包含的数据,哪怕是大小也只不过是个模板参数。和普通使用‘[]’语法申明的数组相比,只不过显得更加高效(操作高效),因为这个类添加了一系列的全局成员函数用来操作这些元素。下面来列一些主要的操作: // ‘[]’ 操作 #include <iostream> #include <array> int main () { std::array<int,10> myarray; unsigned int i; // assign some values: for (i=0; i<10; i++) myarray[i] = i * 10; // print content std::cout << "myarray contains:"; for(int &i : myarray) std::cout << " " << i; std::cout << std::endl; return 0; } 运行结果: C:\Windows\system32\cmd.exe /c array.exe myarray contains: 0 10 20 30 40 50 60 70 80 90 Hit any key to close

c++:智能指针(weak_ptr)

房东的猫 提交于 2020-01-16 00:54:14
1.weak_ptr到底是什么? 简单的说就是weak_ptr是shared_ptr的一个助手,是为了配合shared_ptr而引入的一种智能指针,它指向一个由shared_ptr管理的对象而不影响所指对象的生命周期,也就是将一个weak_ptr绑定到一个shared_ptr不会改变shared_ptr的引用计数。不论是否有weak_ptr指向,一旦最后一个指向对象的shared_ptr被销毁,对象就会被释放。 2.为什么需要weak_ptr? 多个shared_ptr实例可以指向同一个动态对象,并维护了一个共享的引用计数器。对于引用计数法实现的计数,总是避免不了循环引用(或环形引用)的问题,这个时刻就需要智能指针 weak_ptr 例子: #include <iostream> #include <memory> #include <vector> using namespace std; class ClassA { public: ClassA() { cout << "ClassA Constructor..." << endl; } ~ClassA() { cout << "ClassA Destructor..." << endl; } shared_ptr<ClassB> pb; // 在A中引用B }; class ClassB { public: ClassB()

Why does cout prevent subsequent code from running here?

拟墨画扇 提交于 2020-01-15 09:54:08
问题 I'm working on a rudimentary shell, but in the loop below, the program doesn't run past the marked line (it immediately loops instead). When I comment it out, the entire block completes before looping again. What's going on here? #include <iostream> #include <string> #include <stdlib.h> using namespace std; int main(int argc, char *argv[]) { string input; const char *EOF="exit"; string prompt=getenv("USER"); prompt.append("@ash>"); while(true) { int parent=fork(); if ( !parent ) { cout <<

Why does cout prevent subsequent code from running here?

大兔子大兔子 提交于 2020-01-15 09:54:08
问题 I'm working on a rudimentary shell, but in the loop below, the program doesn't run past the marked line (it immediately loops instead). When I comment it out, the entire block completes before looping again. What's going on here? #include <iostream> #include <string> #include <stdlib.h> using namespace std; int main(int argc, char *argv[]) { string input; const char *EOF="exit"; string prompt=getenv("USER"); prompt.append("@ash>"); while(true) { int parent=fork(); if ( !parent ) { cout <<

No match for 'operator<<' in std::cout [duplicate]

老子叫甜甜 提交于 2020-01-15 03:45:06
问题 This question already has answers here : no match for ‘operator<<’ in ‘std::operator (4 answers) Closed 2 years ago . I am developing gsoap web service where I am retrieving vectors of objects in return of a query. I have two ways to do it: first by simple loop and by iterator. None of them working. The error is: error: no match for 'operator<<' in 'std::cout mPer.MultiplePersons::info.std::vector<_Tp, _Alloc>::at<PersonInfo, std::allocator<PersonInfo> >(((std::vector<PersonInfo>::size_type)i

输入输出优化(提高读入输出速度)

岁酱吖の 提交于 2020-01-14 12:08:11
参考 https://blog.csdn.net/weixin_43960287/article/details/85337291 1.用scanf,printf代替cin,cout 2.取消同步和绑定 ios :: sync_with_stdin ( false ) ; cin . tie ( 0 ) ; //cout.tie(0); 此时只能用cin,cout 3.对整型输入输出,将每个数字变成字符 inline int read ( ) { int x = 0 ; int f = 1 ; char s = getchar ( ) ; while ( s < '0' or s > '9' ) { if ( s == '-' ) f - = 1 ; s = getchar ( ) ; } while ( s >= '0' and s <= '9' ) { x = x * 10 + s - '0' ; s = getchar ( ) ; } return x * f ; } void write ( int x ) { if ( x / 10 > 0 ) write ( x / 10 ) ; putchar ( char ( x % 10 + '0' ) ) ; } int main ( ) { //freopen("input.txt","r",stdin); int n =

STL set 使用小结

对着背影说爱祢 提交于 2020-01-14 02:48:35
这是微软帮助文档中对集合(set)的解释: “描述了一个控制变长元素序列的对象(注:set中的key和value是Key类型的,而map中的key和value是一个pair结构中的两个分 量)的模板类, 每一个元素包含了一个排序键(sort key)和一个值(value)。对这个序列可以进行查找、插入、删除序列中的任意一个元素,而完成这些操作的时间同这个序列中元素个数的对数成比例关 系, 并且当游标指向一个已删除的元素时,删除操作无效。” 而一个经过更正的和更加实际的定义应该是:一个集合(set)是一个容器,它其中所包含的元素的值是唯一的。这在收集一个数据的具体值的时候是有用的。集 合中的元素按一定的顺序排列,并被作为集合中的实例。如果你需要一个键/值对(pair)来存储数据,map是一个更好的选择。一个集合通过一个链表来组 织,在插入操作和删除操作上比向量(vector)快,但查找或添加末尾的元素时会有些慢。 #include<iostream> #include<string> #include<set> using namespace std; int main() { set<string> strset; set<string>::iterator iter; strset.insert("apple"); strset.insert("orange"); strset

Make a wrapper for cout?

血红的双手。 提交于 2020-01-14 02:12:30
问题 So here's an interesting question, How would I make something kinda like a wrapper for cout? I want to be able to add it into a dll so I can throw it into my programs. but the basic syntax of it should be Mything::mesage << "I'm some text" << im_an_int << someclass << mything::endl; or Mything::mesageandlog << "I'm going to print to console, and to a file!" << mything::endl; I can handle most of the internal logic but as to what I should put to even do this. kinda stumped. Possibly make a

PointConv论文

半世苍凉 提交于 2020-01-13 22:14:33
转载请注明作者和出处: http://blog.csdn.net/john_bh/ 论文链接: PointConv: Deep Convolutional Networks on 3D Point Clouds 作者及团队:Zhengxia Zou & Zhenwei Shi & Yuhong Guo & Jieping Ye 会议及时间: CVPR 2019 code: github:https://github.com/DylanWusee/pointconv 文章目录 Abstract 1.Introduction 1.1. 作者为什么研究这个课题? 1.2. 目前这个课题的研究进行到了哪一阶段? 3. PointConv 3.1. Convolution on 3D Point Clouds 3.2. Feature Propagation Using Deconvolution 4. Efficient PointConv 5. Experiments 5.1. Classification on ModelNet40 5.2. ShapeNet Part Segmentation 5.3. Semantic Scene Labeling 5.4. Classification on CIFAR10 6. Ablation Experiments and