【发布时间】:2012-08-20 10:33:28
【问题描述】:
我的目标是建立一个数据结构来存储我的应用程序的设置。
在 PHP 中我只会写...
$settings = array(
"Fullscreen" => true,
"Width" => 1680,
"Height" => 1050,
"Title" => "My Application",
);
现在我尝试在 C++ 中创建一个类似的结构,但它还不能处理不同的数据类型。顺便说一句,如果有更好的方法来存储这些设置数据,请告诉我。
struct Setting{ string Key, Value; };
Setting Settings[] = {
("Fullscreen", "true"), // it's acceptable to store the boolean as string
("Width", "1680"), // it's not for integers as I want to use them later
("Height", 1050), // would be nice but of course an error
("Title", "My Application") // strings aren't the problem with this implementation
};
如何使用flexible datatypes 为associative array 的结构建模?
【问题讨论】:
-
通常人们会简单地使用一个结构。为什么需要灵活的数据类型或关联数组?