Timeline for How to read data from a Vector
Current License: CC BY-SA 4.0
Post Revisions
18 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| S Dec 15, 2021 at 19:29 | vote | accept | Omar | ||
| S Dec 15, 2021 at 19:29 | vote | accept | Omar | ||
| S Dec 15, 2021 at 19:29 | |||||
| Dec 2, 2021 at 14:42 | review | Close votes | |||
| Dec 6, 2021 at 0:06 | |||||
| Dec 2, 2021 at 14:41 | vote | accept | Omar | ||
| S Dec 15, 2021 at 19:29 | |||||
| Dec 2, 2021 at 14:36 | comment | added | molbdnilo | Read the introduction to iterators in your favourite C++ book. | |
| Dec 2, 2021 at 14:36 | answer | added | Slava | timeline score: 2 | |
| Dec 2, 2021 at 14:30 | answer | added | Caleth | timeline score: 3 | |
| Dec 2, 2021 at 14:30 | comment | added | Abdur Rakib |
With size_t it's far easier to loop without error. Simply vector_name[i] will give the value at i index.
|
|
| Dec 2, 2021 at 14:29 | comment | added | Slava |
@AbdurRakib in this case it is not, OP declared it as an int
|
|
| Dec 2, 2021 at 14:29 | comment | added | 001 |
Side note: I find range based for loops easier to work with: for (auto b : Verification) { ... }
|
|
| Dec 2, 2021 at 14:29 | comment | added | Abdur Rakib |
Also it is iterator. Kinda like pointer. So, change it==true to *it==true.
|
|
| Dec 2, 2021 at 14:28 | comment | added | Omar | @AbdurRakib that does look a lot better but what do I check for true or false in that for loop | |
| Dec 2, 2021 at 14:28 | comment | added | Caleth |
Aside: *it==true is the same as *it, is the same as (*it == true) == true. Just use the bool value directly
|
|
| Dec 2, 2021 at 14:27 | comment | added | Abdur Rakib |
I don't think the error is the operator. You are declaring it as int but trying to put an iterator in it. Change int to vector<bool>::iterator. Although, personally I prefer this style- for(size_t i = 0; i < vector_name.size(); i++)
|
|
| Dec 2, 2021 at 14:27 | answer | added | Richard | timeline score: 1 | |
| Dec 2, 2021 at 14:26 | comment | added | Caleth |
int it = Verification.begin() should be a compile error too.
|
|
| Dec 2, 2021 at 14:26 | comment | added | Borgleader | *it, an iterator itself is not true or false it points to an element of the container that may be true or false, also your iterator shouldnt be an int | |
| Dec 2, 2021 at 14:23 | history | asked | Omar | CC BY-SA 4.0 |