Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

So here are my 2 cents.

  1. You should reserve the memory of your vectors beforehand. If you do not know the actual number of lines you should still be able to guess it more or less correctly from the size of the file. What you really want is to avoid constant reallocations, which are guaranteed when pushing hundreds of thouthands of elements.

  2. Have a look here: http://stackoverflow.com/questions/11719538/how-to-use-stringstream-to-separate-comma-separated-strings https://stackoverflow.com/questions/11719538/how-to-use-stringstream-to-separate-comma-separated-strings

In short you can pass an additional separating token to the stringstream, which eliminates the need for modifying the string of the line

So here are my 2 cents.

  1. You should reserve the memory of your vectors beforehand. If you do not know the actual number of lines you should still be able to guess it more or less correctly from the size of the file. What you really want is to avoid constant reallocations, which are guaranteed when pushing hundreds of thouthands of elements.

  2. Have a look here: http://stackoverflow.com/questions/11719538/how-to-use-stringstream-to-separate-comma-separated-strings

In short you can pass an additional separating token to the stringstream, which eliminates the need for modifying the string of the line

So here are my 2 cents.

  1. You should reserve the memory of your vectors beforehand. If you do not know the actual number of lines you should still be able to guess it more or less correctly from the size of the file. What you really want is to avoid constant reallocations, which are guaranteed when pushing hundreds of thouthands of elements.

  2. Have a look here: https://stackoverflow.com/questions/11719538/how-to-use-stringstream-to-separate-comma-separated-strings

In short you can pass an additional separating token to the stringstream, which eliminates the need for modifying the string of the line

Source Link
miscco
  • 4.4k
  • 12
  • 17

So here are my 2 cents.

  1. You should reserve the memory of your vectors beforehand. If you do not know the actual number of lines you should still be able to guess it more or less correctly from the size of the file. What you really want is to avoid constant reallocations, which are guaranteed when pushing hundreds of thouthands of elements.

  2. Have a look here: http://stackoverflow.com/questions/11719538/how-to-use-stringstream-to-separate-comma-separated-strings

In short you can pass an additional separating token to the stringstream, which eliminates the need for modifying the string of the line

lang-cpp

AltStyle によって変換されたページ (->オリジナル) /