Home > Back-end >  Great god solve,,,,,,, about the container,,,
Great god solve,,,,,,, about the container,,,

Time:09-30

 # include & lt; Iostream> 
#include
using namespace std;


Int main (int arg c, char * argv [])
{
Int a=0, b=0, I;
The vector & lt; Int> Vec1;
The vector & lt; Int> Vec2.

While (1) {
Cout<& lt;" Please enter an integer: ";
Cin> i;
If (i> 0)
Vec1. Push_back (I);
a++;
The else {
If (i<0)
Vec2. Push_back (I);
b++;
The else {
If (I==0)
break;
The else {
Cout<& lt;" Input is not an integer! Please input again ~ ~ "& lt; continue;
}
}

}

}
Cout<& lt;" The number of positive integers is: "& lt; Cout<& lt;" Respectively is: ";
For (vector : : iterator iter=vec1. The begin (); Vec1! (=end); Vec1 + +) {
Cout<* vec1 & lt; & lt;" ";
}
Cout<& lt;" Negative integer number is: "& lt; Cout<& lt;" Respectively is: ";
For (vector : : iterator iter=vec2. The begin (); Vec2! (=end); Vec2 + +) {
Cout<* vec2 & lt; & lt;" ";
}
return 0;
}




Then write can run???

CodePudding user response:

Write wrong, all the vector loop output data, using iterators, not a vector object itself

CodePudding user response:

#include
#include
using namespace std;


Int main (int arg c, char * argv [])
{
Int a=0, b=0, I;
The vector & lt; Int> Vec1;
The vector & lt; Int> Vec2.

While (1)
{
Cout<& lt;" Please enter an integer: ";
Cin> i;

If (i> 0)
{//here enclosed
Vec1. Push_back (I);
a++;
}
The else
{
If (i<0)
{//here also enclosed
Vec2. Push_back (I);
b++;
}
The else
{
If (I==0)
{
break;
}
The else
{
Cout<& lt;" Input is not an integer! Please input again ~ ~ "& lt; continue;
}
}

}

}
Cout<& lt;" The number of positive integers is: "& lt; Cout<& lt;" Respectively is: ";

//note that there is an iterator operations, not a vector
For (vector : : iterator iter=vec1. The begin (); Iter!=vec1. End (); Iter++)
{
Cout<* iter<& lt;" ";
}

Cout<& lt;" Negative integer number is: "& lt; Cout<& lt;" Respectively is: ";
For (vector : : iterator iter=vec2. The begin (); Iter!=vec2. End (); Iter++)
{
Cout<* iter<& lt;" ";
}

system("pause");
return 0;
}

CodePudding user response:

 
#include
#include
using namespace std;


Int main (int arg c, char * argv [])
{
Int a=0, b=0, I;
The vector & lt; Int> Vec1;
The vector & lt; Int> Vec2.

While (1)
{
Cout<& lt;" Please enter an integer: ";
Cin> i;

If (i> 0)
{//here enclosed
Vec1. Push_back (I);
a++;
}
The else
{
If (i<0)
{//here also enclosed
Vec2. Push_back (I);
b++;
}
The else
{
If (I==0)
{
break;
}
The else
{
Cout<& lt;" Input is not an integer! Please input again ~ ~ "& lt; continue;
}
}

}

}
Cout<& lt;" The number of positive integers is: "& lt; Cout<& lt;" Respectively is: ";

//note that there is an iterator operations, not a vector
For (vector : : iterator iter=vec1. The begin (); Iter!=vec1. End (); Iter++)
{
Cout<* iter<& lt;" ";
}

Cout<& lt;" Negative integer number is: "& lt; Cout<& lt;" Respectively is: ";
For (vector : : iterator iter=vec2. The begin (); Iter!=vec2. End (); Iter++)
{
Cout<* iter<& lt;" ";
}

system("pause");
return 0;
}

CodePudding user response:

thank god!!!!!!!!!!