cout

boost::dynamic_bitset

半腔热情 提交于 2020-01-09 15:45:39
#include <boost/dynamic_bitset.hpp> using namespace boost; int main() { // 构造函数 dynamic_bitset<> db; // 空 dynamic_bitset<> db1(10); // 大小为10 dynamic_bitset<> db2(0x16, BOOST_BINARY(11101));// 大小为22 dynamic_bitset<> db3(std::string("0100")); // 大小为4 dynamic_bitset<> db4(db2); dynamic_bitset<> db5 = db3; cout << db2.to_ulong() << endl;// 29 转换为整数 cout << db3.to_ulong() << endl;// 4 // dynamic_bitset内部由高到底存储二进制位 // 访问 cout << db3[0];// 0 cout << db3[1];// 0 cout << db3[2];// 1 cout << db3[3] << endl;// 0 db3[0] = 1;// 非0就会置为1 cout << db3[0];// 1 cout << db3[1];// 0 cout << db3[2];// 1 cout << db3

boost::tuple

删除回忆录丶 提交于 2020-01-09 15:39:36
// 忽略警告 #define _SCL_SECURE_NO_WARNINGS #pragma warning(disable : 4996) #include <assert.h> #include <iostream> #include <boost/tuple/tuple.hpp> #include <boost/ref.hpp>//boost::cref(i) #include <boost/tuple/tuple_comparison.hpp>// 比较操作 #include <boost/tuple/tuple_io.hpp>// io操作 #include <boost/assign.hpp> using namespace boost; using namespace std; using namespace boost::assign; template <typename Tuple> void print_tuple(const Tuple& t) { cout << t.get_head() << ','; print_tuple(t.get_tail());// 递归输出 } // 用于终止上述的递归输出 void print_tuple(const boost::tuples::null_type& t) { cout << endl; } int

boost 序列化

。_饼干妹妹 提交于 2020-01-09 15:35:43
#include "stdafx.h" #include <iostream> using namespace std; #include <boost/archive/binary_iarchive.hpp> #include <boost/archive/binary_oarchive.hpp> using namespace boost::archive; #include <sstream> int main() { int a = 10; // 4 string s("你好!"); // 序列化时字节是9 cout << s.size() << endl;// 5字节长度(2字节/汉字 + 4字节(成员大小)) uint32_t b = 23; // 4 string ss("abcdfrg"); // 序列化时字节是11(7字母 + 4字节(成员大小)) cout << ss.size() << endl; int64_t c = 2456; // 8 // char、double会有问题 //char d = 'a'; //double e = 3.14; std::stringstream os; boost::archive::binary_oarchive arSend(os, boost::archive::no_header); arSend << a <<

Accelerate C++ 学习笔记7 第三章 使用批量数据 习题

一个人想着一个人 提交于 2020-01-09 12:31:11
//0 # include <iostream> # include <algorithm> # include <string> # include <ios> //streamsize # include <iomanip> //setprecision # include <vector> using std :: cout ; using std :: cin ; using std :: endl ; using std :: sort ; using std :: streamsize ; using std :: vector ; using std :: setprecision ; using std :: string ; int main ( int argc , char const * argv [ ] ) { cout << "Please enetr your name:" ; string name ; cin >> name ; cout << "Hello, " << name << "!" << endl ; cout << "Please enter your midterm and final exam grades:" ; //其中期末成绩 double midterm , final ; cin >> midterm >> final

what is the best way to avoid negative zero in output?

你离开我真会死。 提交于 2020-01-09 11:36:46
问题 As in this question is said, there is some differences between negative and positive zero in floating point numbers. I know it's because of some important reasons. what I want to know is a short code to avoid negative zero in output. for example in the following code: cout << fixed << setprecision(3); cout << (-0.0001) << endl; "-0.000" is printed. but I want "0.000". Note all other negative numbers (e.g. -0.001) should still be printed with the minus sign preceding them, so simply * -1 will

what is the best way to avoid negative zero in output?

别来无恙 提交于 2020-01-09 11:35:09
问题 As in this question is said, there is some differences between negative and positive zero in floating point numbers. I know it's because of some important reasons. what I want to know is a short code to avoid negative zero in output. for example in the following code: cout << fixed << setprecision(3); cout << (-0.0001) << endl; "-0.000" is printed. but I want "0.000". Note all other negative numbers (e.g. -0.001) should still be printed with the minus sign preceding them, so simply * -1 will

C++ 输入输出重定向

狂风中的少年 提交于 2020-01-09 00:34:52
C++中流(stream)是一个对象,所以任何有流这种行为的对象也是流对象。 流主要分为三种类型: istream: 主要是从流中执行输入操作 ostream:主要是从流中执行输出操作 iostream:主要是从流中执行输入输出操作 每个流对象都关联一个流buffer,程序一般从buffer中读取数据,所以如果要重定向流,只需要把buffer对象指向另外一个流即可。 所有的流对象都关联了一个类成员数据streambuf,它就是stream的缓冲区(buffer)。C++读取输入输出的时候是从buffer中读取,而不是源数据流读取。 我们执行重定向操作使用ios::rdbuf()方法。对于这个方法,如果不传参数,那么直接返回流对象的buffer指针。如果传递了某个流对象的buffer指针,那么将当前的流对象绑定到那个传递过来的流对象的buffer上。 例子: stream_object.rdbuf(); //返回流对象buffer stream_object.rdbuf(streambuf * p); //绑定流对象buffer 实际操作: // cout 重定向到文件 #include <fstream> #include <iostream> #include <string> using namespace std; int main() { fstream file; //

c++模板常量可变类型

谁说胖子不能爱 提交于 2020-01-08 09:40:24
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> #include <type_traits> #include <iostream> struct S { void f() { std ::cout << "invoked non-cv-qualified S.f()" << std ::endl; } void f() const { std ::cout << "invoked const S.f()" << std ::endl; } void f() volatile { std ::cout << "invoked volatile S.f()" << std ::endl; } void f() const volatile { std ::cout << "invoked const volatile S.f()" << std ::endl; } }; template < class T > void invoke() { T t; (( T *)&t)->f(); } int main() { invoke< S >(); invoke< std :: add_const < S >:: type >(); invoke< std :: add_volatile < S >:: type >(); invoke< std :: add

网页跳转(多个栈)

最后都变了- 提交于 2020-01-08 03:00:18
题目要求: 蒜头君每天都在用一款名为“蒜厂浏览器”的软件。在这个浏览器中,一共三种操作:打开页面、回退和前进。它们的功能如下: 打开页面:在地址栏中输入网址,并跳转到网址对应的页面; 回退:返回到上一次访问的页面; 前进:返回到上次回退前的页面,如果上一次操作是打开页面,那么将无法前进。 现在,蒜头君打开浏览器,进行了一系列操作,你需要输出他每次操作后所在页面的网址。 输入格式 第一行输入一个整数 n(0 < n \le 100000)n(0<n≤100000),表示蒜头君的操作次数。 接下来一共 nn 行,每行首先输入一个字符串,如果是VISIT,后面接着输入一个不含有空格和换行的网址(网址长度小于 100100),表示蒜头君在浏览器地址栏中输入的网址;如果是BACK,表示蒜头君点击了回退按钮;如果是FORWARD,表示蒜头君点击了前进按钮。 输出格式 对于每次操作,如果蒜头君能操作成功,输出蒜头君操作之后的网址,否则输出Ignore。假设蒜头君输入的所有网址都是合法的。 样例输入 10 VISIT https://www.jisuanke.com/course/476 VISIT https://www.taobao.com/ BACK BACK FORWARD FORWARD BACK VISIT https://www.jisuanke.com/course/429

How to count an array content and assign number position with php

白昼怎懂夜的黑 提交于 2020-01-07 08:00:33
问题 am working on a website project in which i fetch array from my database and use foreach statement to output its contents. I want use php script to count how many items are in the array and assign number position to each item so that if the number position of the first item is an odd number i will apply css float:left style to it but if its even number it will float:right any help please??. thank you. 回答1: Use the modulus operand: <?php foreach ( $array as $index => $item ): ?> <div class="<