c++吓到我了,这是什么情况,从没遇到过

末影人014 2020-04-24 09:45:55
我本来写一个代码,小程序:
#include <iostream>

#include <cstdio>

#include <algorithm>

using namespace std;

int k = 0;

struct Student
{
string name,adress,Class;
int number;
}stud[1001];

void AddValue()
{
int a;
cout<<"学号:(返回输入0)";
cin>>a;
if(a != 0) stud[k].number = a;
else return;
printf("姓名:");
cin>>stud[k].name;
printf("班级:(注:输入格式:x年x班)");
cin>>stud[k].Class;
printf("地址:");
cin>>stud[k].adress;
k++;
}

void look()
{
int i;
cout<<"学号 姓名 班级 地址"<<endl;
cout<<"===================="<<endl;
for(i = 0;i < k;i++)
{
cout<<stud[i].number<<' '<<stud[i].name<<' '<<stud[i].Class;
cout<<' '<<stud[i].adress<<endl<<endl<<endl;
}
}

void finum()
{
int a,i;
cout<<"请输入学号:";
cin>>a;
for(i = 0;i < k;i++) if(a == stud[i].number) break;
cout<<stud[i].number<<' '<<stud[i].name<<' '<<stud[i].Class;
cout<<' '<<stud[i].adress<<endl<<endl<<endl;
}

void fn()
{
string a;
int i;
cout<<"请输入姓名:";
cin>>a;
for(i = 0;i < k;i++) if(a == stud[i].name) break;
cout<<stud[i].number<<' '<<stud[i].name<<' '<<stud[i].Class;
cout<<' '<<stud[i].adress<<endl<<endl<<endl;
}

void fc()
{
string a;
int i;
cin>>a;
cout<<"请输入班级:";
for(i = 0;i < k;i++) if(a == stud[i].Class) break;
cout<<stud[i].number<<' '<<stud[i].name<<' '<<stud[i].Class;
cout<<' '<<stud[i].adress<<endl<<endl<<endl;
}

void fia()
{
string a;
int i;
cout<<"请输入地址:";
cin>>a;
for(i = 0;i < k;i++) if(a == stud[i].adress) break;
cout<<stud[i].number<<' '<<stud[i].name<<' '<<stud[i].Class;
cout<<' '<<stud[i].adress<<endl<<endl<<endl;
}

bool ZBPM(Student x,Student y)
{
return x.name > y.name;
}

bool xbpm(Student x,Student y)
{
return x.number < y.number;
}

int main()
{
int Choise,a;
while(1)
{
cout << "****************************\n";
cout << "* 学生基本信息管理系统 *\n";
cout << "*==========================*\n";
cout << "* 1、录入学生信息 *\n";
cout << "* 2、显示学生信息 *\n";
cout << "* 3、查询学生信息 *\n";
cout << "* 4、学生信息排序 *\n";
cout << "* 5、删除学生信息 *\n";
cout << "* 6、修改学生信息 *\n";
cout << "* 0、退出管理系统 *\n";
cout << "****************************\n";
cout << "请选择:";
cin>>Choise;
if(Choise == 1) AddValue();
else if(Choise == 2) look();
else if(Choise == 3)
{
cout<<"1.找学号 2.找名字 3.找班级 4.找地址 0.退出"<<endl;
cin>>a;
if(a == 1) finum();
else if(a == 2) fn();
else if(a == 3) fc();
else if(a == 4) fia();
}
else if(Choise == 4)
{
int l;
cout<<"1.按字典序排序(从小到大) 2.按学号排序(从小到大)";
cin>>l;
if(l == 1) sort(a,a + k,ZBPM);
else if(l == 2) sort(a,a + k,xbpm);
cout<<"已完成!";
}
}
return 0;
}
结果编译错误,出现了一个我从来没见过的东西(新建来一个cpp),是这样的:
// Types used in iterator implementation -*- C++ -*-

// Copyright (C) 2001-2014 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// Under Section 7 of GPL version 3, you are granted additional
// permissions described in the GCC Runtime Library Exception, version
// 3.1, as published by the Free Software Foundation.

// You should have received a copy of the GNU General Public License and
// a copy of the GCC Runtime Library Exception along with this program;
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
// <http://www.gnu.org/licenses/>.

/*
*
* Copyright (c) 1994
* Hewlett-Packard Company
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Hewlett-Packard Company makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*
*
* Copyright (c) 1996-1998
* Silicon Graphics Computer Systems, Inc.
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation. Silicon Graphics makes no
* representations about the suitability of this software for any
* purpose. It is provided "as is" without express or implied warranty.
*/

/** @file bits/stl_iterator_base_types.h
* This is an internal header file, included by other library headers.
* Do not attempt to use it directly. @headername{iterator}
*
* This file contains all of the general iterator-related utility types,
* such as iterator_traits and struct iterator.
*/

#ifndef _STL_ITERATOR_BASE_TYPES_H
#define _STL_ITERATOR_BASE_TYPES_H 1

#pragma GCC system_header

#include <bits/c++config.h>

#if __cplusplus >= 201103L
# include <type_traits> // For _GLIBCXX_HAS_NESTED_TYPE, is_convertible
#endif

namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION

/**
* @defgroup iterators Iterators
* Abstractions for uniform iterating through various underlying types.
*/
//@{

/**
* @defgroup iterator_tags Iterator Tags
* These are empty types, used to distinguish different iterators. The
* distinction is not made by what they contain, but simply by what they
* are. Different underlying algorithms can then be used based on the
* different operations supported by different iterator types.
*/
//@{
/// Marking input iterators.
struct input_iterator_tag { };

/// Marking output iterators.
struct output_iterator_tag { };

/// Forward iterators support a superset of input iterator operations.
struct forward_iterator_tag : public input_iterator_tag { };

/// Bidirectional iterators support a superset of forward iterator
/// operations.
struct bidirectional_iterator_tag : public forward_iterator_tag { };

/// Random-access iterators support a superset of bidirectional
/// iterator operations.
struct random_access_iterator_tag : public bidirectional_iterator_tag { };
//@}

/**
* @brief Common %iterator class.
*
* This class does nothing but define nested typedefs. %Iterator classes
* can inherit from this class to save some work. The typedefs are then
* used in specializations and overloading.
*
* In particular, there are no default implementations of requirements
* such as @c operator++ and the like. (How could there be?)
*/
template<typename _Category, typename _Tp, typename _Distance = ptrdiff_t,
typename _Pointer = _Tp*, typename _Reference = _Tp&>
struct iterator
{
/// One of the @link iterator_tags tag types@endlink.
typedef _Category iterator_category;
/// The type "pointed to" by the iterator.
typedef _Tp value_type;
/// Distance between iterators is represented as this type.
typedef _Distance difference_type;
/// This type represents a pointer-to-value_type.
typedef _Pointer pointer;
/// This type represents a reference-to-value_type.
typedef _Reference reference;
};

/**
* @brief Traits class for iterators.
*
* This class does nothing but define nested typedefs. The general
* version simply @a forwards the nested typedefs from the Iterator
* argument. Specialized versions for pointers and pointers-to-const
* provide tighter, more correct semantics.
*/
#if __cplusplus >= 201103L

_GLIBCXX_HAS_NESTED_TYPE(iterator_category)

template<typename _Iterator,
bool = __has_iterator_category<_Iterator>::value>
struct __iterator_traits { };

template<typename _Iterator>
struct __iterator_traits<_Iterator, true>
{
typedef typename _Iterator::iterator_category iterator_category;
typedef typename _Iterator::value_type value_type;
typedef typename _Iterator::difference_type difference_type;
typedef typename _Iterator::pointer pointer;
typedef typename _Iterator::reference reference;
};

template<typename _Iterator>
struct iterator_traits
: public __iterator_traits<_Iterator> { };
#else
template<typename _Iterator>
struct iterator_traits
{
typedef typename _Iterator::iterator_category iterator_category;
typedef typename _Iterator::value_type value_type;
typedef typename _Iterator::difference_type difference_type;
typedef typename _Iterator::pointer pointer;
typedef typename _Iterator::reference reference;
};
#endif

/// Partial specialization for pointer types.
template<typename _Tp>
struct iterator_traits<_Tp*>
{
typedef random_access_iterator_tag iterator_category;
typedef _Tp value_type;
typedef ptrdiff_t difference_type;
typedef _Tp* pointer;
typedef _Tp& reference;
};

/// Partial specialization for const pointer types.
template<typename _Tp>
struct iterator_traits<const _Tp*>
{
typedef random_access_iterator_tag iterator_category;
typedef _Tp value_type;
typedef ptrdiff_t difference_type;
typedef const _Tp* pointer;
typedef const _Tp& reference;
};

/**
* This function is not a part of the C++ standard but is syntactic
...全文
775 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
末影人014 2020-04-26
  • 打赏
  • 举报
回复
引用 2 楼 寻开心 的回复:
大惊小怪的, sort函数没有用对, 你自己看看a是什么类型, int
传参不对
if(l == 1) sort(a,a + k,ZBPM);
else if(l == 2) sort(a,a + k,xbpm);

错误是模板函数, 编译到时候自动打开的标准cpp文件, 无需更改他, 改你自己的代码去
对不起哈,其实我发帖一会就发现问题了,只不过24小时内无法结帖,谢谢哈
寻开心 2020-04-25
  • 打赏
  • 举报
回复
大惊小怪的, sort函数没有用对, 你自己看看a是什么类型, int
传参不对
if(l == 1) sort(a,a + k,ZBPM);
else if(l == 2) sort(a,a + k,xbpm);

错误是模板函数, 编译到时候自动打开的标准cpp文件, 无需更改他, 改你自己的代码去
末影人014 2020-04-24
  • 打赏
  • 举报
回复
救命啊,有人吗

65,212

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧