简体   繁体   English

如何在数组和向量中存储和保持输入C ++

[英]How to store and keep input in arrays and vectors c++

How do I store input in vectors and arrays in c++ from multiple user input? 如何将来自多个用户输入的输入存储在C ++中的向量和数组中? Like if 'sally' stored '10' in my cin >> function and then 'john' stored '11' in another cin >> function what is the correct formatting I have to do using my arrays and vectors? 就像如果'sally'在我的cin >>函数中存储了'10',然后'john'在另一个cin >>函数中存储了'11',那么我使用数组和向量必须做的正确格式化是什么? :/ I need to keep those numbers for later how do i differentiate between the two (and others stored later on) when I have to use them :/我需要保留这些数字,以便以后在必须使用它们时如何区分两者(以及以后存储的其他数字)

edit: so i have to calculate bowling scores so once someone enters their name (i have that cout function written) they will cin >> their name and then the code will say "Enter scores" and i have it in a for loop so that it will say first roll score: second roll score: and so on. 编辑:所以我必须计算保龄球得分,所以一旦有人输入他们的名字(我写了cout函数),他们就会cin >>他们的名字,然后代码会说“输入得分”,我将它放在for循环中,这样它会说第一声名得分:第二声名得分:等等。 so whenever they enter in their name and then their scores how do i keep those scores related to their name. 因此,无论何时他们输入他们的名字,然后输入分数,我如何保持这些分数与他们的名字相关。 and then someone will enter another name once the first persons scores are all entered. 输入第一人称分数后,有人将输入另一个名称。 what kind of vector or array should i use to store the persons name with the scores? 我应该使用哪种矢量或数组来存储带有分数的人员姓名? heres my code so far : https://repl.it/@aladcox2000/lab5c yes i know a lot of the code is wrong but just so you can see what i am doing and how it relates to my question. 到目前为止,这是我的代码: https : //repl.it/@aladcox2000/lab5c是的,我知道很多代码是错误的,但是您可以看到我在做什么以及它与我的问题的关系。 hopefully this clarifies :-) 希望这可以澄清:-)

您可以使用std::unordered_map<std::string, int> -这样可以将名称存储为键,将数字存储为值。

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

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