gpt4 book ai didi

c++ - 在 main 中包含 header 时出现 undefined reference 错误

转载 作者:搜寻专家 更新时间:2023-10-31 00:26:14 27 4
gpt4 key购买 nike

<分区>

所以我的程序有三个文件。我的 main.cpp 看起来像这样:

#include <iostream>
#include <fstream>
#include <cstdlib>
#include "dtt0055HW4func.cpp"
#include "dtt0055HW4func.h"
using namespace std;
int main()
{
int size = 7;
char (*boardOfGame)[7] = new char[7][7];
int* sizeOfBoardGame = NULL;
sizeOfBoardGame = &size;
initializeBoardGame(boardOfGame, sizeOfBoardGame);
return 0;
}

我的 func.h 看起来像这样:

#ifndef dtt0055HW4func 
#define dtt0055HW4func

enum typeOfTiles{CROSS = '+', HORIZONTAL = '-', VERTICAL = '|', LOCKED = 'X', EMPTY};
enum colorOfTiles{RED, BLUE};
struct tile{
typeOfTiles newTile;
colorOfTiles newTileColor;
int positionOfNewTile;
};
void initializeBoardGame(char (*boardOfGame)[7],int* sizeOfBoard);

#endif

谢谢,伙计,你在第一个错误上提供的帮助。我修改了我的程序,它在 func.cpp 中给了我一个新问题。现在我的 func.cpp 看起来像这样:

#include "dtt0055HW4func.h"
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;

void initializeBoardGame(char (*boardOfGame)[7],int* sizeOfBoard)
{
char nameOfFile[30],c;
ifstream inFS;

cout << "Please enter the name of the input file: ";
cin >> nameOfFile;

inFS.open(nameOfFile);
if (inFS.fail())
{
while(inFS.fail())
{
cout << "Unable to open the file, please enter the name of the file again. " << endl;
cin >> nameOfFile;
inFS.open(nameOfFile);
}
}

while (!inFS.eof())
{
for (int i = 0; i < *sizeOfBoard; i++)
{
for (int j = 0; j < *sizeOfBoard; j++)
{
boardOfGame[i][j] = &inFS.get(c);
cout << boardOfGame[i][j];
}
cout << endl;
}
}
inFS.close();
}

现在我的编译器在 func.cpp 中给我一个错误错误:从‘std::basic_istream::__istream_type* {aka std::basic_istream*}’到‘char’的无效转换[-fpermissive] boardOfGame[i][j] = &inFS.get(c);我在这一行中试图做的是将文件中的一个字符分配给数组的一个索引。如果我使用 boardOfGame[i][j] = inFS.get(c);,它会给我更多的错误。

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