歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> C++ vector<string> 內聯函數

C++ vector<string> 內聯函數

日期:2017/3/1 10:07:25   编辑:Linux編程

vector<string> 的內聯函數

內聯函數的好處:

一般調用函數前首先要保存寄存器,並在返回時恢復。復制實參,程序還必須轉向一個新位置執行。而寫成內聯函數,將避免函數調用的開銷,將它在程序中的每個調用點上‘內聯的’展開。

內聯函數應該在頭文件中定義,這一點不同於其它函數。

  1. inline vector<string>& split(string& str, char delim, vector<string>& elems)
  2. {
  3. stringstream ss(str);
  4. string item;
  5. elems.clear();
  6. while(getline(ss, item, delim))
  7. {
  8. elems.push_back(item);
  9. }
  10. return elems;
  11. }
Copyright © Linux教程網 All Rights Reserved