On 09/20/11 03:05 PM, sravanreddy001 wrote:
> Hi,
>
> Can anyone give the best way (faster) to write the vector contents to a file?
>
> Is there a better way to do it than below method?
>
> for(unsigned i=0;i<terms.size();i++){
> sprintf(temp,"%d %s\n",i,terms[i].c_str());
> ids_n_terms = ids_n_terms + temp;
> }
Where do you do the write?
> Is the string addition a very expensive operation? (will a new memory allocation takes place)
>
> there are around 5,00,000 (strings) in the vector, and these have to stored in
> <id term> format.
You will probably be I/O limited, so optimising your code won't make any
significant difference.
--
Ian Collins
|