随笔分类 - C/C++
git 常用命令
摘要:$ git remote -v #查看远程主机的网址$ git fetch <远程主机名> # 将某个远程主机的更新,全部取回本地$ git fetch <远程主机名> <分支名> # 取回origin主机的master分支$ git branch -r # 查看远程分支$ git branch -
阅读全文
[c++] stack的使用
摘要:1 #include<iostream> 2 #include<stack> 3 #include<deque> 4 using namespace std; 5 6 7 int main() 8 { 9 stack<int> first;10 cout << "size of first: " &
阅读全文
[c++] vector的使用
摘要:1 #include<iostream> 2 #include<vector> 3 using namespace std; 4 5 void print( vector<int> &vec ) 6 { 7 for ( vector<int>::iterator it = vec.begin();
阅读全文
struct和typedef struct的区别
摘要:当typedef与结构结合使用时,会有一些比较复杂的情况,而且在C语言和C++里面有略有差别,因此从网上摘录了一些资料。1 首先:在C中定义一个结构体类型要用typedef:typedef struct Student{int a;}Stu;于是在声明变量的时候就可:Stu stu1;如果没有typedef就必须用struct Student stu1;来声明这里的Stu实际上就是struct Student的别名。另外这里也可以不写Student(于是也不能struct Student stu1;了)typedef struct{int a;}Stu;但在c++里很简单,直接struct S
阅读全文
有趣的逻辑运算符
摘要:逻辑运算符号也是一种运算符号,比如&&(与)、||(或)和!(非)。一般自己在写C/C++程序的时候,通常用逻辑运算符做判断,if(A且B)或者while(A或B),很少用他们做算数运算。因为用逻辑运算符做算数运算,就要涉及到二进制数的每一个bit的值了。今天在找分段树算法的时候发现几个有趣的面试题,关于逻辑运算符的例子。第一个是y=x&&(-x)。这个式子的返回值是最后一位“1”以及其后所有“0”组成的数。比如,设x=40,用二进制表达就是x=00101000。-x=-40,负数在计算机里是用补码表示的(补码就是反码加一,反码是原码取反),-x=1101100
阅读全文
This application failed to start because it could not find or load the Qt platform plugin “windows”错误解决方法
摘要:这是一个困扰我很久的问题,关于Qt下生成的exe文件在没有安装Qt的机器上无法运行的问题。Qt是编写C++图形界面的一个很好工具,比MFC来的直观。可是,Qt的安装却是一个让人头疼的事情。早在上个学期,我就在windows XP 系统下安装了Qt 4.8,用破解版的msvc 2010编译。安装过程中出现了多次“configure is not an internal or external command”之类的问题,安装卸载了多次,好在最后可以使用。之后又安装了破解版的ipp包,当我把生成的exe文件移到另一台电脑上安装使用时,总是提示缺少dll,或者XXX错误。鉴于都是破解版的软件,我不知
阅读全文
如何优雅的写C++代码(一)
摘要:// get the greatest power of two that is a divisor of n: return n&-n; // swap two integers a and b: a^=b^=a^=b; a^=b, b^=a, a^=b; // check whether a (nature number > 1) is a power of two or not: return ( ! ( x & (x-1))); return (x&-x) == x; // count number of bits set in v: for( int i
阅读全文
Color Map的生成方法
摘要:/* Return a RGB colour value given a scalar v in the range [vmin,vmax] In this case each colour component ranges from 0 (no contribution) to 1 (fully saturated), modifications for other ranges is trivial. The colour is clipped at the end of the scales if v is outside the range [vmin,vmax]*...
阅读全文
浙公网安备 33010602011771号