Hi
I suspect using std::stringstream is not big enough. Could that be? In fact I need to store around 20'000 characters. How to set std::stringstream size?
Many thanks
Hi
I suspect using std::stringstream is not big enough. Could that be? In fact I need to store around 20'000 characters. How to set std::stringstream size?
Many thanks
HiI suspect using std::stringstream is not big enough. Could that be? In fact I need to store around 20'000 characters. How to set std::stringstream size?
Many thanks
I suspect using std::stringstream is not big enough
[/quote]
Care to explain what did you really mean?
How to set std::stringstream size?
[/quote]
You are not allowed to manually set size as far as i know, but you can manipulate objects stored in it so you control its size indirectly.
But what you can do is reserve memory for 20000 characters, to easy process of reallocation for space each time you add character.
Michaels-MacBook-Pro:~ mjbshaw$ cat t.cpp
#include <iostream>
#include <sstream>
int main()
{
std::stringstream ss;
for (int i = 0; i < 20000; ++i)
ss << i << '\n';
std::string str = ss.str();
std::cout << "There are " << str.size() << " characters in ss and str\n";
std::cout << "The contents of ss and str are:\n" << str;
}
Michaels-MacBook-Pro:~ mjbshaw$ g++ t.cpp && ./a.out
There are 108890 characters in ss and str
The contents of ss and str are:
0
1
2
3
4
[...] (I'm not going to post all 20,000 numbers)
@Cornstalks: how many characters in str total though? Also how much would be the sizeof occupied. would it be depending on systems configuration.
I raised the loop and hehe, it did go up to 438888890 for i < 50000000. I gueess its is has no size limitations. :)
@Cornstalks: how many characters in str total though? Also how much would be the sizeof occupied. would it be depending on systems configuration.
Crap. I'm sorry, I tapped my mousepad and didn't realize my mouse was right over the "vote down" button and accidentally gave this post a -1. I've tried to counter-act that accident by voting up the post below it. Sorry!
Now to respond to your question: There is no set size limit for std::string (or any container, for that matter). The limit is your system. If std::string needs more memory, it will request more memory from the operating system. If the operating system has it, it will give it more. If it doesn't, then your program will fail (well, technically a std::bad_alloc exception will be thrown).