1

我厌倦了谷歌搜索如何在托管 C++ 应用程序中使用 user.config 而不是 app.config。我发现的只是 C#,我不知道如何翻译成 C++(属性命名空间不存在)

任何人都可以让我了解这一点吗?我需要知道如何创建、读取和写入 user.config 文件。

谢谢

4

1 回答 1

6

按照以下步骤操作,它将按预期工作:

1 - 添加引用System.Configuration

2 - Add New Item> Visual C++> Utility>Configuration file

3 - 打开app.config并添加您的设置,例如:

<configuration>
  <appSettings>
    <add key="greeting" value="Hallo world!" />
  </appSettings>
</configuration>

4 - 将 复制app.config到构建后事件中的输出文件夹:goto Project Properties> Configuration Properties> Build Events> Post-Build Events>Command Line并添加:

copy app.config "$(TargetPath).config"

5 - 阅读您的设置:

String^ greeting = ConfigurationManager::AppSettings["greeting"];
Console::WriteLine(greeting);

这是一个AppConfigDemo项目C++/CLI

于 2014-12-06T12:57:26.720 回答