【发布时间】:2013-01-11 17:43:45
【问题描述】:
void Lexicon::buildMapFromFile(string filename ) //map
{
ifstream file;
file.open(filename.c_str() );
string wow, mem, key;
unsigned int x = 0;
while(true) {
getline(file, wow);
if (file.fail()) break; //check for error
while (x < wow.length() ) {
if (wow[x] == ',') {
key = mem;
mem.clear();
x++; //step over ','
} else
mem += wow[x++];
}
list_map0.put(key, mem); //char to string
list_map1.put(mem, key); //string to char
mem.clear(); //reset memory
x = 0;//reset index
}
file.close();
}
此函数读取一个 2 列的 csv 文件并创建一个以 column1 作为键的 column2 的映射。我用 g++ 编译,文件在大学文件共享上,当我用 ./foo 运行程序时,csv 文件 [在与 foo 相同的目录文件夹中] 未被读取......为什么?
【问题讨论】:
-
当您尝试运行时收到什么消息?
-
#Hassan TM 程序运行正常,但从 cout 检查我可以看到文件未被读取