- 请在通过电子邮件回复时删除资金''A' 我没有回复最热门的回复,请不要'不要问 *更正*'''pckset''应该是''modpckset''。 pe******@gmail.com 写道: 这是为了什么? V - 请删除资金'' A'在回复电子邮件时我没有回复最热门的回复,请不要问 *更正*' 'pckset''应该是''modpckset''。 好的。通过删除 getline(fp,linestr)之间的界限,可以提高整个代码段的效率; 和 } ;他们基本上没有任何会产生副作用的工作。 创建一个字符串流,从中读取内容,以及将这些未签名的内容放入本地集合中的是浪费 CPU周期。 V - 请删除大写''A'通过电子邮件回复 我没有回复最热门的回复,请不要问 Dear comp.lang.c++,Could you make this snippet more efficient? As you see I have too manyvariables introduced in the code.//Read set of integers from a file on line by line basis in a STL set//fp is pre-definedfor(;!fp.eof();){string linestr;getline(fp,linestr);istringstream strstreamline(linestr);istream_iterator<unsigned intintstream(strstreamline);set<unsigned intpckset;copy ( intstream , istream_iterator<unsigned int>() ,inserter(modpckset,modpckset.begin ( ) ));}Thanks in advance. 解决方案What''s that for?V--Please remove capital ''A''s when replying by e-mailI do not respond to top-posted replies, please don''t askWhat''s that for?V--Please remove capital ''A''s when replying by e-mailI do not respond to top-posted replies, please don''t ask*Correction* ''pckset'' should have been ''modpckset''. What''s that for? V--Please remove capital ''A''s when replying by e-mailI do not respond to top-posted replies, please don''t ask*Correction* ''pckset'' should have been ''modpckset''.OK. The entire snippet can be made more efficient by removingthe lines betweengetline(fp, linestr);and}; they do essentially no work that would have side effects.The creation of a stringstream, reading stuff from it, andputting those unsigned ints into a local set are a waste ofCPU cycles.V--Please remove capital ''A''s when replying by e-mailI do not respond to top-posted replies, please don''t ask 这篇关于STL:你能否让这个片段更有效率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-12 11:24