我只是想打开一个名为“test.txt”的文件,其中包含:
cat
dog
moose
rabbit
然后我想从文件中读取并将其内容转换为字符串,以便稍后在程序中执行。到目前为止,我认为我正在朝着正确的方向前进。但是,我收到一个错误,我不确定该怎么做。这是错误>>>
$ make -f makefile.txt
g++ -g -D HASH_TABLE_SIZE=10 -c hash.cpp
hash.cpp: In member function `void Hash::processFile(std::string)':
hash.cpp:12: error: no match for 'operator>>' in 'my_infile >> word'
makefile.txt:6: recipe for target `hash.o' failed
make: *** [hash.o] Error 1
这是我到目前为止的代码(因此无法编译)
void Hash::processFile(string filename)
{
string word;
Hash HashTable;
ifstream my_infile(const char* filename, ios_base::openmode mode = ios_base::in);
while(my_infile >> word)//iterate through the file and hash them (handles collisions too)
{
//Insert keys and handle collisions
}
}