【发布时间】:2011-02-13 16:18:17
【问题描述】:
我有一个简单的包类,它被重载了,所以我可以简单地用 cout
protected:
string name;
string address;
double weight;
double shippingcost;
ostream &operator<<( ostream &output, const Package &package )
{
output << "Package Information ---------------";
output << "Recipient: " << package.name << endl;
output << "Shipping Cost (including any applicable fees): " << package.shippingcost;
第 4 行出现问题(输出
我猜这与数据类型是包名称的字符串有关。有什么想法吗?
【问题讨论】:
-
您使用的是 std::string 还是其他字符串库?
-
Using string.h #include
它在我的这个类的 .h 和 .cpp 文件中。还使用命名空间 std(尽管其他行应该清楚这一点)。 -
使用
<string>-<string.h>是非标准的,可能会做一些奇怪的事情。<iostream>等也是如此。 -
您是否尝试过包含#include
? -
@gf:我认为 string.h 是标准的。然而,与 C 兼容的不是 .h 版本的字符串,而是 .h 版本的 cstring。
标签: c++ polymorphism overloading cout