好吧,所以我试图使用wifstream从我的.txt文件中读取并放入我的结构中。我不断遇到与此代码有关的问题:请告诉我我需要了解什么以及为什么它失败。谢谢
我有8个错误,它们都是:

std::basic_istream<wchar_t,std::char_traits<wchar_t>>::getline': none of the 2 overloads could convert all the argument types
std::basic_istream<wchar_t,std::char_traits<wchar_t>>::getline': illegal call of non-static member function
std::basic_istream<wchar_t,std::char_traits<wchar_t>>::getline': illegal call of non-static member function
std::basic_istream<wchar_t,std::char_traits<wchar_t>>::getline': illegal call of non-static member function
a nonstatic member reference must be relative to a specific object
a nonstatic member reference must be relative to a specific object
a nonstatic member reference must be relative to a specific object
std::basic_ifstream<_Elem, _Traits>::getline [with _Elem=wchar_t, _Traits=std::char_traits<wchar_t>]" matches the argument list


码:

#include "stdafx.h"
#include <Windows.h>
#include <Commctrl.h>
#include <Windowsx.h>
#include <shellapi.h>
#include <TlHelp32.h>
#include <wchar.h>
#include <fstream>

//SQL Headers
//Add SQL later with option to store games location.

//Macros Tab1
#define IDB_BUTTONLAUNCH 100
#define IDB_PROCESSCHECKBOX 101

//Macros Tab2
#define IDB_SQLRADIOBUTTON 201
#define IDB_NOTEPADRADIOBUTTON 202

#pragma comment(linker,"\"/manifestdependency:type='win32' \
name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")

int numberAdder = 0;
int *numberAdderPTR = &numberAdder;

struct gameSaved
{
    int gameID = 0;
    static wchar_t szGameDirectory[100];
    static wchar_t szApplicationName[100];
    static wchar_t szComboName[100];
};

wchar_t gameSaved::szGameDirectory[100];
wchar_t gameSaved::szApplicationName[100];
wchar_t gameSaved::szComboName[100];
gameSaved gameList[50];




void WndProc (etc) // This is just representing that it is all global.
{
            std::wifstream savedGames;
            savedGames.open(L"ComboBox Saved Games.txt");
             //Error Code is with all the std::wifstream::getline below
            while (std::wifstream::getline(gameList[numberAdder].gameID, 2))
            {
                std::wifstream::getline(gameList[numberAdder].szGameDirectory, MAX_PATH);
                std::wifstream::getline(gameList[numberAdder].szApplicationName, MAX_PATH);
                std::wifstream::getline(gameList[numberAdder].szComboName, MAX_PATH);
                ComboBox_AddString(hComboBoxTab1, gameList[numberAdder].szComboName);
                *numberAdderPTR = gameList[numberAdder].gameID + 1;
            }
    }

最佳答案

getlinestatic的非std::wifstream成员。因此,使用以下内容是不合法的:

std::wifstream::getline( ... );


您需要一个对象来进行呼叫。

std::wifstream input;
input.getline( ... );

关于c++ - 用struct&wifstream非法调用非静态成员函数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33207170/

10-13 00:26