简体   繁体   English

如何在字符串向量中指向 const int?

[英]how can i make a pointing to const int inside a string vector?

im trying to make a program where costumers info gets stored struct, and pointers.我试图制作一个程序,其中客户信息被存储结构和指针。 but i cant get a vector to point to a const value.但我不能让一个向量指向一个常量值。

struct costumer{ 
   string name;
   string email_adress;
   int *subscription ????
}

i can add the costumer name, and email_adress but im trying to have the struct store the sold subscribtion.我可以添加客户姓名和电子邮件地址,但我试图让结构存储已售出的订阅。 so for example someone bought a yearly subscription of television for const $100 a year.例如,有人以每年 100 美元的价格购买了年度电视订阅。 I add subscribtion then television then 100 it should display television(100).我添加订阅然后电视然后 100 它应该显示电视(100)。 costumer can have multiple subscriptions stored in a vector.客户可以将多个订阅存储在一个向量中。 so subscriptions = {television(100), internet(50),...,netflix(20)}.所以订阅 = {television(100), internet(50),...,netflix(20)}。 so if ask to see what subscriptions a costumer has.因此,如果要求查看客户有哪些订阅。 it displays these.它显示这些。 if im not really clear sorry english is not y first language.如果我不是很清楚对不起英语不是你的第一语言。

Subscriptions should have information of both what he subscribed to and cost.订阅应包含他订阅的内容和费用的信息。 int* is not sufficient to store both. int* 不足以存储两者。 one of the possible solutions may be creating subscription structure.一种可能的解决方案可能是创建订阅结构。

typedef struct subscription{
 string subscribed_to;
 int    cost;
 }subscription;

struct customer{
 string name;
 string email_id;
 int num_of_subscriptions;
 subscription subs[20];
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM