C++ string parsing (python style)

后端 未结 10 1149
伪装坚强ぢ
伪装坚强ぢ 2020-12-08 07:52

I love how in python I can do something like:

points = []
for line in open(\"data.txt\"):
    a,b,c = map(float, line.split(\',\'))
    points += [(a,b,c)]
<         


        
10条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-08 08:40

    all these are good examples. yet they dont answer the following:

    1. a CSV file with different column numbers (some rows with more columns than others)
    2. or when some of the values have white space (ya yb,x1 x2,,x2,)

    so for those who are still looking, this class: http://www.codeguru.com/cpp/tic/tic0226.shtml is pretty cool... some changes might be needed

提交回复
热议问题