Getline with WinApi - Using WOFSTREAM / WIFSTREAM - C++ / WI

Getline with WinApi - Using WOFSTREAM / WIFSTREAM - C++ / WIN32

本文关键字:WIFSTREAM C++ WI Using with WinApi Getline WOFSTREAM      更新时间:2023-10-16

我使用的是Windows 10 (Visual Studio 2015)。

好的,我想说的是,我用一个编辑框让用户写一个目录,appname,comboboxname然后让wofstream输出目录,appname,comboboxname到一个。txt文件

我的问题是,一些目录有空间,所以当wifstream读取这些空间,然后切断目录到早期,并将切断的版本存储到一个wchar_t变量。

我需要程序做的(我不确定它是否可能)是逐行输出。

的例子:

C:Program Files (x86)Minecraft

MinecraftLauncher

"我

然后使用getline读取整行,包括空格,将该行存储到一个变量中,然后获取下一行。(但它也不能抓取任何不在目录中的额外空白,否则它将无法工作)你们可能知道目录是如何工作的lol)

你们不用费劲看,我希望这个在IDB_CLICK_ME的情况下发生

这是我目前的代码,在我决定将其添加到我的主应用程序之前,我正在修补它:

这是我试图读取文件(没有空白)

case WM_CREATE:
    {

        wchar_t testData[20] = L"Hai";
        CreateWindow(L"button", L"CLICK ME", WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON, 5, 5, 200, 25, hwnd, (HMENU)IDB_CLICK_ME, NULL, NULL);
        comboBox = CreateWindow(L"combobox", L" ", WS_VISIBLE | WS_CHILD | CBS_DROPDOWNLIST, 5, 50, 100, 100, hwnd, (HMENU)4, NULL, NULL);
        hProgramName = CreateWindow(L"edit", L"Program Name", WS_VISIBLE | WS_CHILD | WS_BORDER | ES_AUTOHSCROLL, 5, 100, 200, 25, hwnd, NULL, NULL, NULL);
        hProgramDirectory = CreateWindow(L"edit", L"Program Directory", WS_VISIBLE | WS_CHILD | WS_BORDER | ES_AUTOHSCROLL, 5, 130, 200, 25, hwnd, NULL, NULL, NULL);
        hProgramNameComboBox = CreateWindow(L"edit", L"Name listed in ComboBox", WS_VISIBLE | WS_CHILD | WS_BORDER | ES_AUTOHSCROLL, 5, 160, 200, 25, hwnd, NULL, NULL, NULL);
        std::wifstream myfile;
        myfile.open("LaunchLocations.txt");
        myfile >> std::noskipws >> gameLaunchtest.directory;
        myfile >> std::noskipws >> gameLaunchtest.AppName;
        myfile >> std::noskipws >> gameLaunchtest.ComboBoxName;

这是我写它的地方,到目前为止,这是正确的

    ComboBox_AddString(comboBox, gameLaunchtest.directory);
    break;

        case WM_COMMAND:
            switch (LOWORD(wparam))
            {
            case IDB_CLICK_ME:
                    GetWindowText(hProgramDirectory, gameLaunchtest.directory, MAX_PATH);
            GetWindowText(hProgramName, gameLaunchtest.AppName, MAX_PATH);
            GetWindowText(hProgramNameComboBox, gameLaunchtest.ComboBoxName, MAX_PATH);
            wofstream launchLocations;
            launchLocations.open("LaunchLocations.txt");
            launchLocations << gameLaunchtest.directory << endl;
            launchLocations << gameLaunchtest.AppName << endl;
            launchLocations << gameLaunchtest.ComboBoxName << endl;
            launchLocations.close();

所以我解决我的问题的方式(我被一些非常帮助的成员告诉我,我必须使用wifstream getline而不是字符串getline)

    std::wifstream myfile;
    while (myfile.getline(test[number].directory, 100))
        {
            myfile.getline(test[number].AppName, 100);
            myfile.getline(test[number].ComboBoxName, 100);
            test[number].ID;
            ComboBox_AddString(comboBox, test[number].ComboBoxName);
            number++;
            test[number].ID = test[number].ID + 1;