Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/129.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;排序无法解析标识符开始和结束?(将数组保持在一起)_C++_Sorting_Netbeans_Bubble Sort - Fatal编程技术网

C++ C++;排序无法解析标识符开始和结束?(将数组保持在一起)

C++ C++;排序无法解析标识符开始和结束?(将数组保持在一起),c++,sorting,netbeans,bubble-sort,C++,Sorting,Netbeans,Bubble Sort,我试图按int对数组对进行排序,但排序结果是“无法将标识符解析”为pairs.begin()、pairs.end()和compare\u pairs\u second()。我不知道为什么,但我可能做错了什么? 这是我的密码: #include <iostream> #include <string> #include <cstdlib> #include <iomanip> #include <algorithm> #include &

我试图按int对数组对进行排序,但排序结果是“无法将标识符解析”为pairs.begin()、pairs.end()和compare\u pairs\u second()。我不知道为什么,但我可能做错了什么? 这是我的密码:

#include <iostream>
#include <string>
#include <cstdlib>
#include <iomanip>
#include <algorithm>
#include <iterator>
using namespace std;
main()
{
string name[10];//declaring an array name
int number[10];//declaring an array number

cout << "Please input 10 names \n";//output
for(int i = 0; i < 10; i++){//for statement
    cin >> name[i];//inputting names in the array names
}
cout << "Please input their corresponding numbers \n";//output
for(int x = 0; x < 10; x++){
    cin >> number[x];//inputting numbers
}//end for
int i = 0;//redeclaring i to be 0
int x = 0;//redeclaring x to be 0
for(int l = 0; l < 10; l++)//for statement
{
    cout << name[i] << ": " << number[x] << "\n";
    i++;//adding 1 to i so outputs all of array name
    x++;//adding 1 to x so outputs all of array number
}//end for
pair<string, int> pairs[10];
int i = 0;
int x = 0;
for(int z = 0; z < 10; z++)
{
    pairs[z] = make_pair(name[i], number[x]);
    i++;
    x++;
}
std::sort(pairs.begin(), pairs.end(), compare_pairs_second<std::less>());
int i = 0;
int x = 0;
for(int z = 0; z < 10; z++)
{
    name[i] = pairs[z].first;
    number[x] = pairs[z].second;
    i++;
    x++;
}
string search = "";
cout << "Enter a name to search for";
cin >> search;
size_t found = pairs.find(search);
if(found!=string::npos)
    cout << search << pairs;
} //end main
#包括
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
main()
{
字符串名称[10];//声明数组名称
整数[10];//声明一个数组数
cout>name[i];//在数组名称中输入名称
}
cout>数[x]//输入数字
}//结束
int i=0//将i重新定义为0
int x=0//将x重新定义为0
for(int l=0;l<10;l++)//for语句
{

cout
pairs
是原始数组,不是STL容器;不能像
pairs.begin()
pairs.end()
那样对其调用方法

由于C++11,您可以使用and,and重载以支持原始数组

std::sort(std::begin(pairs), std::end(pairs), compare_pairs_second<std::less>());
std::sort(std::begin(pairs),std::end(pairs),compare_pairs_second());

我更改了我的代码以查看您的解决方案是否有效,它仍然给了我无法解析开始和结束的标识符,但用于比较的标识符消失了。@Griffinflame编译器是否支持C++11?是的,我刚刚检查过,它支持。@Griffinflame
比较对秒的定义在哪里
?我在您的代码中找不到它。@Griffinflame最好发布一个。您可以尝试使用
std::array pairs;
std::sort(std::begin(pairs), std::end(pairs), compare_pairs_second<std::less>());