NSUserDefaultsまたはCFPreference、レジストリでによる文字列の保存方法です。 下記はそれぞれについてのサンプルです。
#import <Cocoa/Cocoa.h> NSString *name = @"kuran_kuran"; NSUserDefaults* userdefaults = [NSUserDefaults standardUserDefaults]; [userdefaults setObject:name forKey:@"name"]; [userdefaults synchronize];
#import <Cocoa/Cocoa.h> NSString *name; NSUserDefaults* userdefaults = [NSUserDefaults standardUserDefaults]; name = [userdefaults stringForKey:@"name"];
#include <CoreFoundation/CFPreferences.h> CFStringRef application_name; CFNumberRef value; int score; application_name = CFSTR("application_name"); // kCFPreferencesCurrentApplicationを設定するとデフォルトの名前が適用される score = 125; value = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &score); CFPreferencesSetAppValue(CFSTR("score"), value, application_name); CFRelease(value); CFPreferencesAppSynchronize(application_name);
#include <CoreFoundation/CFPreferences.h> CFStringRef application_name; CFNumberRef value; int score; application_name = CFSTR("application_name"); // kCFPreferencesCurrentApplicationを設定するとデフォルトの名前が適用される value = CFPreferencesCopyAppValue(CFSTR("score"), application_name); if(value) { CFNumberGetValue(value, kCFNumberIntType, &score); CFRelease(value); }
#include <tchar.h> #include <windows.h> int score; score = 125; result = RegCreateKeyEx(HKEY_CURRENT_USER, _T("SOFTWARE\\REGISTRYTEST"), 0, _T(""), REG_OPTION_NON_VOLATILE, KEY_CREATE_SUB_KEY | KEY_WRITE, NULL, &handle, NULL); if(result == ERROR_SUCCESS) { RegSetValueEx(handle, _T("score"), 0, REG_DWORD, reinterpret_cast<CONST BYTE*>(&score), sizeof(DWORD)); RegCloseKey(handle); }
#include <tchar.h> #include <windows.h> int score; result = RegOpenKeyEx(HKEY_CURRENT_USER, _T("SOFTWARE\\REGISTRYTEST"), 0, KEY_READ, &handle); if(result == ERROR_SUCCESS) { DWORD type; DWORD size; result = RegQueryValueEx(handle, _T("score"), NULL, &type, NULL, &size); if((result == ERROR_SUCCESS) && (type == REG_DWORD)) { RegQueryValueEx(handle, _T("score"), NULL, &type, reinterpret_cast<LPBYTE>(&score), &size); } RegCloseKey(handle); }
前に戻る?