/* 完整样例 A */
#include <iostream>
#include <sstream>
std::stringstream& operator<<(std::stringstream& os, double d)
{
os.operator<<(d);
return os;
}
int main()
{
double d;
std::cin >> d;
std::cout << (std::stringstream() << d).str().length() << std::endl;
return 0;
}
/* 代码片段 B */
#include <map>
#include <string>
#include <stdexcept>
struct key_error
: public std::logic_error
{
explicit key_error(std::string const& what)
: std::logic_error(what)
{}
};
std::string const& lookup(std::map<std::string, std::string> const& map
, std::string const& key)
throw(key_error)
{
std::map<std::string, std::string>::const_iterator i = map.find(key);
if (map.end() == i) {
throw key_error("key ``" + key + "'' not found in map");
}
return i->second;
}
lookup
函数有什么隐患?答案已揭晓, 点此查看, 谢谢关注.