从TextFile中读取数字,并检查它们是否在范围内

read numbers from textfile, and check if they are in range

本文关键字:是否 范围内 检查 TextFile 读取 数字      更新时间:2023-10-16

我正在尝试加载带有1000个数字或类似内容的文本文件,我想检查每个数字是否在范围内。我尝试使用矢量,但不能直接我。

基本上,我想检查第一个数字是否更大或=下一个数字,然后进行多次。

ps:我对任何类型的编程都是极端的,所以请不要刻薄:)

这是我的代码:

using namespace std;
int main() {
    ifstream myfile;
    myfile.open ("A1.txt");
    vector<int>array;
    int count;
    double tmp;
    int i;
    myfile >> tmp;
    while (int i = 0; i < count; i++){
        myfile >> tmp;
        array.push_back(tmp);
        cout << count;
    }
    myfile.close();
    return 0;
}

我建议一个循环,直到您阅读每个数字:

...
double previous, tmp;
myfile >> previous;
array.push_back(previous);//this inserts the first element
//but you have to decide if you need it or not, because it is not compared with any value
while (myfile >> tmp){
    array.push_back(tmp);
    if(previous >= tmp){
        //Do something;
    }
    previous = tmp;//the next previous is the current tmp
}
...