1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
#include <vector>
#include <sstream>
#include <string>
using namespace std;
int main()
{
// not unsigned for std::string.
const char binary[]={
1,2,3,4,5,6,7,8,
9,0,1,2,3,4,5,6
};
string str(binary);
vector<char> v;
stringstream ss;
for (unsigned i=0; i<sizeof(binary)/sizeof(char); ++i) {
v.push_back(binary[i]);
ss << binary[i];
}
cout << sizeof(binary)/sizeof(char) << endl; // 16
cout << str.size() << endl; // 9, but it's ok.
cout << v.size() << endl; // 16
cout << ss.str().size() << endl; // 16 <- sure?
vector<char> v2;
while (!ss.eof()) {
v2.push_back(ss.get());
}
cout << v2.size() << endl; // 17 <- why?
cout << (int)v2[v2.size()-1] << endl; // -1 <- why eof pushed?
return 0;
}
|