都江堰建设局官方网站,网站seo思路,怎样才能做好销售,做农家乐网站// structure template { }; 4.4.2 结构可以将 string类作为成员吗 可以将成员name指定为string类对象而不是字符数组吗?即可以像下面这样声明结构吗? #include string struct inflatable std :: string name; float volume; double price; 大体上说,答案是肯定的。实…// structure template { }; 4.4.2 结构可以将 string类作为成员吗 可以将成员name指定为string类对象而不是字符数组吗?即可以像下面这样声明结构吗? #include string struct inflatable std :: string name; float volume; double price; 大体上说,答案是肯定的。实际上,答案取决于您使用的是哪种编译器,因为有些编译器(包括Borland C5.5和7.0版之前的 Microsoft Visual C)不支持对以string对象作为成员的结构进行初始化。 如果您的编译器不支持这种用法,一定要让结构定义能够访问名称空间 std。为此,可以将编译指令 using移到结构定义之前;也可以像前面那样,将name的类型声明为std :: string。 4.4.3 其他结构属性 C使用户定义的类型与内置类型尽可能相似。例如,可以将结构作为参数传递给函数,也可以让函 数返回 …· 个结构。另外,还可以使用赋值操作符()将结构赋给另一个同类型的结构,这样结构中每个 成员都将被设置为另一个结构中相应成员的值,即使成员是数组。这种赋值被称为成员赋值(memberwise assignment),我们将在第7章讨论函数时,再介绍如何传递和返回结构。下面简要地介绍一下结构赋值, 程序清单4.12是一个这样的范例。
}:
{
// assgn_st.cpp -- assigning structures
#include iostream
struct inflatable
char name [20];
float volume:
double price;
int main ()
using namespace std:
inflatable bouquet
sunflowers,
0.20,
12.49
inflatable choice;
cout bouquet: bouquet.name for $;
cout bouquet.price endl:
choice bouquet: // assign one structure to another
cout choice: choice.name for $;
cout choice.price endl;
return 0;
}