gpt4 book ai didi

c++ - 使用 struct 和 wifstream 非法调用非静态成员函数

转载 作者:太空宇宙 更新时间:2023-11-04 13:26:29 39 4
gpt4 key购买 nike

好的,所以我正在尝试使用 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;
}
}

最佳答案

getlinestd::wifstream 的非static 成员。因此,使用:

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

您需要一个对象来进行调用。

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

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

39 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com