阵列上使用std ::排序() [英] using std::sort() on an array

查看:124
本文介绍了阵列上使用std ::排序()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我有从一个文本文件中取数,将它们添加到阵列,并将它们写入文件的程序。
  我需要使用的std :: sort()函数调用数组中的数字进行排序。我在这第一次尝试是这样的:

I have a program which I have got to take numbers from a text file, add them to an array and write them to a file. I need to sort the numbers in the array using the std::sort() function call. My first attempt at it was this:

void ArrayIntStorage::sortStd()
{
    for (int i = 0; i < n; ++ i)
    {
        arrayStorage[i].sort();
    }
}

n是为数组的大小的常数。我知道这是错误的,但林不知道如何takle它。先谢谢了。

"n" is a constant for the size of the array. I know this is wrong but im not sure how to takle it. Thanks in advance.

推荐答案

首先阅读了排序()的文档的这里

First read up the documentation of sort() here

删除循环,只是尽量

std::sort(arrayStorage, arrayStorage + n);

这篇关于阵列上使用std ::排序()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆