hello, c/c++

#include <stdio.h>
#include <string>
#include <iostream>

std::string Hello()
{
    char buf[32] = "Hello Tyson.";
    return buf;
}

char* Hello1()
{
    char buf[32] = "Hello Tyson.";
    return buf;
}

int main()
{
  std::cout << Hello() << std::endl;
  std::cout << Hello1() << std::endl;
  return 0;
}
selnx176:exufhua__ndpgsn_5_0_wb__ndpgsn_5_0_atm532_1:~/hxfan/lib/linux/net> ./a
Hello Tyson.                                                                                                                                                 üp·


Hello()能正常工作, 原因是 std::string 產生臨時變量


&ptr->_val 正常工作, 原因是->比&優先級高


STL algorithm:

find, find_if


gcc中

-DGPBV4   即宏變量GPBV4賦值默認爲1

-DCPU=GPBV4 那麼宏變量CPU現在的值爲1


A* a(new A(5));  這種給指針賦值的方法很屌


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章