我试着写一个非常简单的进度条类.我将所有内容放入progressBar.h中,并创建了一个最小的测试用例.我在Ubuntu 14.04上使用clang ++ 3.4运行它.我包括-std = c ++ 11标志.测试用例创建了一个新的ProgressBar对象并调用成员函数displayProgress(double).我包括在ProgressBar.h中.
这是我的代码:
#include <ostream>
#include <string>
class ProgressBar
{
private:
std::ostream& out;
int width;
public:
ProgressBar(std::ostream& out, int _width = 80)?out(out) {
width = _width - 9;
}
void displayProgress(double percentage) {
out << "\r[" << fixed << setprecision(2) << percentage * 100 << "%]";
for (int i = 0; i < width * percentage; ++i) out << "=";
if (percentage != 1) out << ">";
else out << "O";
}
};
Run Code Online (Sandbox Code Playgroud)
这是错误消息: …