# サンプルプログラム ###### tags:`BveTs` ## 外部ファイルを読み込む ```cpp=1 // c++17以上にすること! #include <filesystem> #include <fstream> #include <sstream> #include <string> BOOL APIENTRY DllMain(HANDLE h, DWORD d, LPVOID l) { if (!loaded) GetCsvFilePath((HMODULE)h); return TRUE; } void GetCsvFilePath(HINSTANCE hModule) { TCHAR dllpath[_MAX_PATH]; GetModuleFileName( hModule, dllpath, sizeof(dllpath) ); filesystem::path folderPath(dllpath); folderPath.remove_filename(); loadCsvData(folderPath); loaded = true; } void loadCsvData(filesystem::path cd) { // ./data/sample.csv を読む filesystem::path filePath = cd; filePath.append("data"); filePath.append("sample.csv"); ifstream csvFile(filePath); if (!csvFile) { MessageBox(NULL, TEXT("sample.csv not found."), TEXT("メッセージボックス"), MB_OK | MB_ICONINFORMATION); return; } string line = ""; string str; while (getline(csvFile, line)) { istringstream getData(line); vector<string> data; while (getline(getData, str, ',')) data.push_back(str); // vectorをここで処理 } } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up