如何基于C ++中文件的输入为枚举赋值?

blc*_*llo 2 c++ file-io enums

我有一个文件,其值如:START和STOP。我还声明了以下枚举:

enum Type {
    START,
    STOP
};
Run Code Online (Sandbox Code Playgroud)

我正在尝试将枚举设置为等于文件中的第一个值,如下所示:

enum Type foo;

ifstream ifile;
ifile.open("input.txt");

ifile >> foo;
Run Code Online (Sandbox Code Playgroud)

我收到错误消息:'ifile >> foo'中的'operator >>'不匹配。

如何正确执行此操作?

pop*_*ter 5

最快的方法是读取int并将其转换为Type枚举。