我正在尝试使用文本文件来初始化将用于初始化 2d 向量的结构,是的,我知道这很复杂,但最终会有很多数据需要处理。问题出在getline,我在其他代码中以这种方式使用它,但由于某种原因它拒绝在这里工作。我不断收到参数错误和模板错误。任何提示将不胜感激。
#include <fstream>
#include <string>
#include <vector>
#include <iostream>
using namespace std;
const int HORIZROOMS=10;
const int VERTROOMS=10;
const int MAXDESCRIPTIONS=20;
const int MAXEXITS=6;
struct theme
{
string descriptions[MAXDESCRIPTIONS];
string exits[MAXEXITS];
};
void getTheme();
int _tmain(int argc, _TCHAR* argv[])
{
getTheme();
vector<vector <room>> rooms(HORIZROOMS, vector<room>(VERTROOMS));
for (int i=0; i<HORIZROOMS; i++)
{
for (int j=0; j<VERTROOMS; j++)
{
cout<<i<<" "<<j<<" "<<rooms[i][j].getRoomDescription()<<endl;
}
}
return 0;
}
void getTheme()
{
theme currentTheme;
string temp;
int numDescriptions;
int numExits;
ifstream themeFile("zombie.txt");
getline(themeFile, numDescriptions, ',');
for (int i=0; i<numDescriptions; i++)
{
getline(themeFile, temp, ',');
currentTheme.descriptions[i]=temp;
}
getline(themeFile, numExits, ',');
for (int i=0; i<numExits; i++)
{
getline(themeFile, temp, ',');
currentTheme.exits[i]=temp;
}
themeFile.close();
}