提问人:Vincent Reiley 提问时间:9/28/2023 最后编辑:Vincent Reiley 更新时间:9/28/2023 访问量:62
将字符串流推送到优先级队列时出错<stringstream>
Error when pushing a stringstream to a priority queue<stringstream>
问:
std::stringstream makeString(std::string name, std::string number) {
std::stringstream ss;
std::string load;
if(number.size() == 1) {
ss << "0" << number << " - " << name << std::endl;
} else {
ss << number << " - " << name << std::endl;
}
return ss;
}
int main(int argc, char const* argv[]) {
// Write your code here
std::string inputs;
std::string priority;
std::priority_queue<std::stringstream> pqueue;
while(1 == 1) {
input("What do you want to do? ", inputs);
if (inputs == "add") {
input("Name: ", inputs);
input("Priority: ", priority);
std::stringstream ss;
ss << makeString(inputs, priority).str();
std::cout << ss.str();
pqueue.push(ss);
} else if (inputs == "take") {
std::stringstream holder;
holder << pqueue.top().str();
pqueue.pop();
std::cout << holder.str() << std::endl;
} else if (inputs == "end") {
return 0;
} else {
std::cout << inputs << " isn't a valid operation" << std::endl;
}
}
}
它应该能够将字符串流推送到优先级队列,但它告诉我它是“对'std::basic_stringstream'的已删除构造函数的调用”
我该如何解决这个问题?我不能在优先级队列中使用字符串流吗?
答: 暂无答案
评论
pqueue.push(std::move(ss));
pqueue.push(std::stringstream("xxx"));
**pqueue.push(ss);**
-- 不要用于突出显示代码行。它可能与指针或取消引用运算符混淆。如果有的话,请执行以下操作:。该代码不仅可编译,而且具有足够的描述性,并且不会将假字符与实际指针和取消引用混淆。*
pqueue.push(ss); // <-- This gives an error
*