检查文本文件中的 0 或 1,并根据结果返回
check a text file for 0 or 1 and return based on result?
我需要帮助检查存储在计算机上的文本文件中的字符串。 伪示例
if String = x {
Sleep(100)
}
else {
exit(0)
}
我只是想检查文本文件中的一行文本,然后根据该行返回一个值......例如,如果字符串continue
那么我希望它继续exit(0)
.
我的C++项目是一个 dll。基本上我要做的是打开一个与dll位于同一位置的文件,检查它是否0
或1
,如果它返回1
则继续该过程0
终止它。
经过一番来回,我相信这就是你想要的
#include <iostream>
#include <fstream>
int main() {
// you probably just want "test.txt" here not "c:\test.txt"
std::ifstream data_store("c:\test.txt");
if (!data_store.good()) {
std::cerr << "couldn't open filen";
return 1;
}
int contents = 0;
data_store >> contents;
if (contents == 0) {
return 0; // or std::exit(0) if not in main
} else if (contents == 1) {
// do the rest of the code here
}
}
相关文章:
- C++Brute Force攻击函数不会返回结果
- 如何在一个表达式中生成并返回结果?
- 使用std::tie进行类似golang的错误处理,同时返回结果,是否有缺点?(C++11)
- C++ 线程端回调并返回结果
- C++使用存储过程返回结果
- reinterpret_cast总是返回结果C++?
- 尝试以随机字符(长读取)打印字符串返回结果
- 通过C 中的参考返回结果
- 使用枚举确定返回结果的类型(使用宏的黑客)
- 返回结果不可见
- 打开一个 Shell 程序,向其传递参数,然后返回结果
- 如何在递归函数中计算返回结果
- 整数列表的交集-无法返回结果列表
- 来自 open() 的返回结果代码之间的差异:25 与 3
- 使用 c++11 线程返回结果的正确方法是什么
- 传递StringBuilder并从c++dll向c#返回结果
- 如何跳出一些深度递归的函数并直接返回结果
- 使用MPI临时接收数据,然后返回结果
- C++,我不知道为什么我的函数不返回结果
- QDialog show()后面跟着返回结果操作