从TextFile中读取数字,并检查它们是否在范围内
read numbers from textfile, and check if they are in range
我正在尝试加载带有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
}
...
相关文章:
- 检查私有成员变量是否在一定范围内,如果没有调整
- 检查IP是否在其他IP网络范围内,并查找下一个可用IP
- 在 c++ 中确定某个值是否在该数据类型的最大范围内
- "std::multimap"是否保证每个键的实际值在相等范围内?
- 初始检查以查看子字符串是否在范围内
- GCC 或 Clang 关于函数参数在其自己的默认参数中的范围内的名称是否正确?
- 如何检查copy_if是否返回使用ostream_iterator范围内的任何内容
- 如果地图擦除范围内的第一个和最后一个相等,则是否删除该元素
- 是否有函数可以检索范围内可用非重复值的数量
- 是否可以在全球范围内声明一个提升线程
- 测试整数是否在范围内时,逻辑错误和不正确输出
- 从TextFile中读取数字,并检查它们是否在范围内
- 如何找出迭代器是否位于某个范围内
- 如何检查字符是否在范围内
- 检查拼写数字是否在C++范围内
- 如何检查一个范围内的值是否是另一个范围内的值的倍数
- 在文件范围内声明互斥是否安全
- 正在检查排序列表中是否有一个范围内的数字
- 是否可以编写一个在函数范围内使用时会抱怨的宏
- 用于检查容器的值是否在范围内的谓词