Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
LongInt i1; cin >> i1;
其中 LongInt 是一个包含整数堆栈的类。我想将输入存储到类的堆栈中,我假设这意味着我必须在类文件中重载 >> 运算符。问题是我不确定如何将诸如 cin >> "111343241" 之类的输入逐位推送到堆栈中。我将如何进行这项工作?
要重载运算符本身,实现 get 循环,定义一个命名空间范围
std::istream& operator >>(std::istream& is, LongInt& li) { char c; while( is.get(c).good() ) { if( !std::isdigit(c) ) { is.unget(); break; } ...push it to li } return is; }
如何将单个数字推送到 LongInt 取决于 LongInt 的实现。