使用struct& amp;非法调用非静态成员函数wifstream

时间:2015-10-19 05:24:32

标签: c++ winapi struct static

好吧所以我试图用wifstream从我的.txt中读取并放入我的结构中。我不断遇到这个代码的问题:请告诉我我需要了解的内容及其失败的原因。谢谢< 3

我有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;
            }
    }

1 个答案:

答案 0 :(得分:0)

getlinestatic的非std::wifstream成员。因此,使用它是不合法的:

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

您需要一个对象来进行通话。

std::wifstream input;
input.getline( ... );
相关问题