Most useful or amazing STL short liners

后端 未结 8 1078
余生分开走
余生分开走 2021-01-29 22:55

I\'m looking for practical and educational samples of C++ / STL code fitting in few lines. My actual favorites are:

  1. Empty a vector freeing its reserved memory:<

8条回答
  •  逝去的感伤
    2021-01-29 23:02

    I like this one for looping over each line in a file. From a Andrew Koenig column in Dr. Dobbs.

    for (string s; getline(stream,s); ) {
      // Process line
    }
    

提交回复
热议问题