Reputation: 57
I am tired of googling about how to use user.config instead of app.config in a managed C++ application. All I found was about C# and I can't figurate out how to translate to C++ (Properties namespace does not exist)
Anybody can put me in the way to learn about that? I need to know how to create, read and write a user.config file.
Thank you
Upvotes: 1
Views: 5526
Reputation: 18665
Follow this steps and it will work like desired:
1 - Add a reference to System.Configuration
2 - Add New Item
> Visual C++
> Utility
> Configuration file
3 - Open app.config
and add your settings for example:
<configuration>
<appSettings>
<add key="greeting" value="Hallo world!" />
</appSettings>
</configuration>
4 - Copy the app.config
to the output folder in the post build event: goto Project Properties
> Configuration Properties
> Build Events
> Post-Build Events
> Command Line
and add this:
copy app.config "$(TargetPath).config"
5 - Read your settings:
String^ greeting = ConfigurationManager::AppSettings["greeting"];
Console::WriteLine(greeting);
Here's an AppConfigDemo project in C++/CLI
.
Upvotes: 9