我有下面的代码,它读取文件格式为# Check for levels
levels(df$group)
# Remove unwanted group
df <- df[df$group != "group_01",]
# Plot the cleaned df
ggplot(df, aes(group, value, fill = group)) + geom_boxplot()
的输入行:{/ 1}}。
我通过operation string [optional argument]
将文件的内容传递给程序。
但是,代码似乎处理文件的最后一行两次。知道为什么会这样吗?
以下是代码:
cat file.txt | ./program
正在处理的文件(#include <iostream>
int main() {
char operation, creditable;
string owner;
double money;
int line=0;
while (std::cin) {
line++;
std::cin >> operation;
try {
switch (operation) {
case 'a':
std::cin >> owner >> creditable;
// code to deal with variables
break;
case 'b':
std::cin >> owner >> money;
// code to deal with variables
break;
case 'c':
std::cin >> owner;
// code to deal with variables
break;
default:
throw std::runtime_error("invalid operation");
break;
}
}
catch (std::runtime_error e) {
std::cerr << "error on line " << line << ": " << e.what() << endl;
}
}
return 0;
}
)如下所示:
file.txt