简体   繁体   中英

C++ store lines of input

I've been stuck on my assignment and I have a general question (don't want my hw answered for me). If I have lines of input such as:

14 14 14 14 14 45 45
18 14 60 10 10 24 12  

and I want to compare each row(take difference of each number; 15-14, etc.) with another line of input such as:

15 15 15 15 20 20 50  

I don't wanna post my code because I'm not looking for someone to do the work for me. What I'm trying right now is to make an Array and use a for loop but I'm not sure how to store each value(separate by space), and I'm not sure how to store 5 rows into an Array .

I'm not allowed to use vectors. I'm only allowed to use iostream, sstream, and string. If anyone can provide a quick answer/hint as to how I would do this that would be great. Thank you

  1. If you just want to know if the numbers are same and having nothing else to do with them.. Read each line and compare the line itself instead of comparing each number. You could use string compare.

treat "14 14 .." as one string and "15 15 .." as the other and compare them

and then the next line and so on..

  1. otherwise

create a 2d array. or an array of pointers. Split the string on 'whitespace' and store each of them as an integer in the array.

Then you could iterate over the arrays and compare them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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