为什么将 std::string 写入 cout 会导致未知运算符<<错误?
Why is writing a std::string to cout causing an unknown operator << error?
当我试图从我的一个方法输出返回值时,我遇到了一个错误:
Error: No operator "<<" matches these operands. Operand types are: std::ostream << std::string
主要.cpp
#include <iostream>
using namespace std;
#include "Book.h"
int main()
{
book.setTitle("Advanced C++ Programming");
book.setAuthorName("Linda", "Smith");
book.setPublisher("Microsoft Press", "One Microsoft Way", "Redmond");
book.setPrice(49.99);
cout << book.getBookInfo(); // <-= this won't compile because of the error above.
int i;
cin >> i;
return 0;
};
应该返回字符串的方法:
string Book::getBookInfo()
{
stringstream ss;
ss << title << endl << convertDoubleToString(price) << endl;
return ss.str();
}
#include <string>
丢失。
代码是如何获得string
的定义的?报头<string>
还声明了流插入器。
相关文章:
- 继承期间显示未知行为的子类
- 请解释这句话(cout<<1+int((a<b)^((b-a)&1) )<<endl
- 呼叫运营商<<临时
- 输入中的字符串数未知(以字母表示)
- 具有未知值时的时间复杂性
- 如何防止clang格式在流运算符调用之间添加换行符<<
- <<操作员在下面的行中工作
- 链表中写入访问冲突的未知原因
- 正在生成未知类实例
- Bjarne Stroustrup Book - std_lib_facilities.h - 不起作用(未知类型名称)
- 读取文件时运行时的未知行为
- 代码在我的计算机上运行良好,但是在将其提交给coursera时遇到未知的信号11问题
- 初始化多个未知基类
- 使用 make 编译 MPI,几个命名空间错误,例如"错误:未知类型名称'使用'?
- 如何存储未知次数迭代的输入?
- QtQuick - qml:28:错误:未知方法返回类型:自定义类型
- 编译 Boost 时在 OS X 上的"ld:未知选项:-soname"
- 未知的 CMake 命令"create_single_source_cgal_program"
- 如何在C++中循环访问未知对象方法?
- std::vector::reserve(未知m),我知道m<<;N(通常)并且知道N