私は C++ でスタンフォード コースの cs106b を行っていますが、行き詰まっていて、正しく理解できないようです。これは、この種のことを知っている人にとってはおそらく非常に簡単な修正です。main.cpp と randword.h と randword.cpp の 3 つのファイルがあります。randword.h には、GetLine() が定義されているスタンフォード ライブラリである #include "simpio.h" があります。main.cpp ファイルで GetLine() を動作させることができますが、コンパイルしようとすると、randword.cpp で「'GetLine()' への未定義の参照」が発生します。
コードブロックを使用し、「ファイルを追加...」機能を使用しました。
main.cpp のコードは次のとおりです。
#include "randword.h"
/* Private function prototypes */
/* Main program */
randword rw;
int main() {
rw.initDictionary();
}
ランダムワード.h:
#ifndef RANDWORD_H_INCLUDED
#define RANDWORD_H_INCLUDED
#include <iostream>
#include <fstream>
#include <stdio.h>
#include "simpio.h"
#include "strutils.h"
using namespace std;
class randword{
public:
void initDictionary();
string chooseRandomWord();
string strArray[];
private:
};
#endif // RANDWORD_H_INCLUDED
ランダム.cpp:
#include "randword.h"
using namespace std;
void randword::initDictionary(){
string fileName;
ifstream infile;
fileName = GetLine();
infile.open(fileName.c_str());
if(infile.fail()) cout << "Couldn't read file.";
return;
}
string randword::chooseRandomWord(){
string st1;
return st1;
}
どんな助けでも大歓迎です!この質問は既に投稿されていると思われますが、見つかりませんでした。ありがとう!