From the Internet to find the code
If only enter a number in a for loop he [I + 1] no error yet but will not don't understand why
The code below
# include & lt; Iostream>
# include & lt; Vector>
using namespace std;
Int main ()
{
Vector
Int ival.
Cout & lt; <"Please enter a number to other non-numeric characters ends:" & lt;
He push_back (ival);
If (he) size ()==0)
{
Cout & lt; <"No one element" & lt;
}
Cout & lt; <"Two adjacent and, in turn, is:" & lt;
For (the decltype (he. The size ()) I=0; I & lt; He. The size () - 1; I +=2)
{
//for two adjacent and
Cout & lt;
If ((I + 2) % 10==0)
Cout & lt;
//if the element is an odd number, alone to deal with the last element
If (he. The size () % 2!=0)
Cout & lt;
}
CodePudding user response:
# include & lt; Iostream>
# include & lt; Vector>
using namespace std;
Int main () {
VectorHe;
Int ival.
Cout & lt; <"Please enter a number to other non-numeric characters ends:" & lt;While (cin & gt;> Ival)
He push_back (ival);
If (he) size ()==0) {
Cout & lt; <"No one element" & lt;return -1;
}
Cout & lt; <"Two adjacent and, in turn, is:" & lt;//use the decltype inference type I
//when only enter a number, he. The size () is 1, the following "I & lt; He. The size () - 1 "do not meet, for not executed
For (the decltype (he. The size ()) I=0; I & lt; He. The size () - 1; I +=2) {
//for two adjacent and
Cout & lt;//every five lines of output five number
If ((I + 2) % 10==0)
Cout & lt;}
//if the element is an odd number, alone to deal with the last element
If (he. The size () % 2!=0)
Cout & lt;system("pause");
return 0;
}
CodePudding user response:
for (the decltype (he. The size (), I=0; I & lt; He. The size () - 1; I +=2)
.//when the input a number, he size ()=1, this is true for (I=0; i<0; +=2), I will not enter the circulation, the implementation of {... } at the back of the statement,
{
Cout & lt;If ((I + 2) % 10==0)//every five lines of output five number
Cout & lt;}