如何打印vector <structure>的内容?

时间:2019-07-10 21:14:42

标签: struct operators

我有一个具有3个整数和一个运算符的结构的代码,我不理解这一部分:public class Startup { public IConfiguration Configuration { get; set; } public Startup() { Configuration = BuildConfiguration(); } // This method gets called by the runtime. Use this method to add services to the container. public IServiceProvider ConfigureServices(IServiceCollection services) { ... } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } ConfigureRoutes(app); } private static void ConfigureMvc(IServiceCollection services, Config config) { services.AddMvc() .SetCompatibilityVersion(CompatibilityVersion.Version_2_2)// auto generated .AddJsonOptions(options => { options.SerializerSettings.Formatting = Formatting.Indented; }) .AddControllersAsServices(); } private static void ConfigureRoutes(IApplicationBuilder app) { //app.UseMvcWithDefaultRoute(); } } ,所以该结构将按x的值排序?以及如何打印vector <(structure)> e的值; ?我之前搜索过,但是很遗憾没有找到任何解决这些问题的方法,如果您想提出任何有关如何学习更多有关结构的参考,谢谢!!

bool operator < (const event &t) const{
    return x < t.x;

错误消息:

using namespace std;

struct event{
int x; //xi -> 0 xf -> 1
int yi,yf; 
int t;  //0 or 1, type of operation that form the rectangle
bool operator < (const event &t) const{
    return x < t.x;
}
}

int main(){
vector<event> e;
int n; cin >> n;
for(int i=0;i<n;i++){
    int xi,yf,xf,yi;
    cin>>yi>>yf>>xf>>yi;
    e.push_back({xi,yi,yf, 0}); 
    e.push_back({xf,yi,yf, 1}); 
}
sort(e.begin(), e.end());
for(auto i : e){          //trying to print, fail
    cout<<i<<" ";
}

return 0;
}

0 个答案:

没有答案