2013年7月30日 星期二

GDB: Missing separate debuginfos

Fixed GDB: Missing separate debuginfos

1. 修改 /etc/yum.repos.d/CentOS-Debuginfo.repo, set enabled=1
2. yum install yum-utils
3. debuginfo-install glibc

如果還是不行更新 gdb and glibc

2012年10月17日 星期三

Translate int to string

#include <iostream>
#include <string>
#include <sstream>

using namespace std;
string int2str(int &);
int main(void{
  int i = 123;
  string s;
  s = int2str(i);

  cout << s << endl;
}


string int2str(int &i) {
  string s;
  stringstream ss(s);
  ss << i;

  return ss.str();
}

2012年10月16日 星期二

判斷奇偶數

利用位元運算來判斷奇偶數

if( (value & 1) == )
  cout << "偶數";
else
  cout << "奇數";

2012年7月3日 星期二

C/C++ 中的括號

在 C語言中的括號分別化表

{ } 大括號表示函式本體的開始與結束
( ) 小括號在函式的宣告中使用

大括號的另類用法,指定了變數的作用範圍,在大括號中的變數都是局部變數,有效區域只在大括號中有效。有效利用這個特性可以使程式簡單明白。


 int a = 5;
  {
    int a = 2;
    printf("Here a=%d!!\n", a);
  }
  printf(" a=%d!!\n", a);