M
Matthew David Hills
If setw() is being used to limit how many characters are pulled from
a stream, should the # of characters taken from the stream depend on
whether the stream is being sent to a std::string or a char*?
string s1;
char s2[256];
cin >> setw(4) >> s1;
cin >> setw(4) >> s2;
(I've found there to be a difference between compilers -- on some,
they results are identical (ie, 3 characters pulled), and on others, the
string receives a 4th character)
Thanks,
Matt
----------------------------------------------------------------------
#include<iostream>
#include<string>
#include<sstream>
#include<iomanip>
using namespace std;
int main(void)
{
string s;
char buffer[256];
istringstream is1("0123456789");
is1 >> setw(4) >> s;
is1.seekg(0);
is1 >> setw(4) >> buffer;
cout << "s = " << s << endl;
cout << "buf= " << buffer << endl;
return 0;
}
a stream, should the # of characters taken from the stream depend on
whether the stream is being sent to a std::string or a char*?
string s1;
char s2[256];
cin >> setw(4) >> s1;
cin >> setw(4) >> s2;
(I've found there to be a difference between compilers -- on some,
they results are identical (ie, 3 characters pulled), and on others, the
string receives a 4th character)
Thanks,
Matt
----------------------------------------------------------------------
#include<iostream>
#include<string>
#include<sstream>
#include<iomanip>
using namespace std;
int main(void)
{
string s;
char buffer[256];
istringstream is1("0123456789");
is1 >> setw(4) >> s;
is1.seekg(0);
is1 >> setw(4) >> buffer;
cout << "s = " << s << endl;
cout << "buf= " << buffer << endl;
return 0;
}