I
Ioannis Vranos
If we want our programs to be protected against buffer overflows, must we
check the size of the various containers explicitly?
E.g.
#include <iostream>
#include <string>
int main()
{
using namespace std;
string s;
while(cin>>s)
;
// ...
}
should become:
#include <iostream>
#include <string>
#include <cctype>
int main()
{
using namespace std;
string s;
while(cin && s.size()<s.max_size())
{
char c;
cin>>c;
if(isspace(c))
continue;
s.push_back(c);
}
// ...
}
Ioannis Vranos
check the size of the various containers explicitly?
E.g.
#include <iostream>
#include <string>
int main()
{
using namespace std;
string s;
while(cin>>s)
;
// ...
}
should become:
#include <iostream>
#include <string>
#include <cctype>
int main()
{
using namespace std;
string s;
while(cin && s.size()<s.max_size())
{
char c;
cin>>c;
if(isspace(c))
continue;
s.push_back(c);
}
// ...
}
Ioannis Vranos