小编use*_*947的帖子

Bash比较数组值以查找最大值

我试图在bash中找到整数数组中的最大值.我对bash很新.这是我到目前为止所拥有的......

    max="${array[0]}"
    for ((i=0;i<${#array[@]};i++))
    do  
        if [ ${array[$i]} > $max ]
        then
            max="${array[$i]}"

        fi
    done
Run Code Online (Sandbox Code Playgroud)

其中数组大约是500个正整数.24 27 13 34 2 104 645 411 1042 38 5 24 120 236 2 33 6.目前它总是返回我的数组中的最后一个整数.似乎它应该是一个简单的解决方案,但我不确定我缺少什么.谢谢你的帮助.

arrays bash

2
推荐指数
1
解决办法
571
查看次数

从C++中的文件中读取IP地址

我正在尝试从文本文件中读取几千个IPv4地址并将它们放入C++字符串数组中.这是我到目前为止所拥有的

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main()
{
    string fileName1,fileName2;
    fileName1="file1Large.txt";
    ifstream inData;
    inData.open(fileName1);
    string file1[10000];
    int i=0;
    while(inData)
    {
        inData>>file1[i];
        i++;
    }
    cout<<"File1: "<<endl;
    for(int z=0; z <= 10000; z++)
    {
        cout<<file1[z];
    }
    inData.close();
    system("pause");
    return 0;

}
Run Code Online (Sandbox Code Playgroud)

当我运行这个时,我得到一个未处理的异常,我不确定是什么问题.我主要使用Java而不是很多C++,所以如果我遗漏了一些明显的东西,我会道歉.

c++ file-io

0
推荐指数
1
解决办法
1506
查看次数

标签 统计

arrays ×1

bash ×1

c++ ×1

file-io ×1