Taking a shot in the dark here because this seems to be the most likely intent. If i'm wrong, hopefully it is still instructional.
#include <iostream>
#include <vector>
I removed the using namespace std that was here because it's dangerous. Don't believe me? Do a quick search. StackOverflow is littered with "WTF is going on?" questions that resolve down to "something in the std namespace had the same name as your variable."
struct boo
{
std::string u;
int p;
};
I've left Boo alone to keep it recognizable to the OP. However, descriptive names really help your code explain itself. No one here, excluding the OP, has any clue what a boo represents and how it should be used or what it's members represent and how they should be used. This limits the our ability to assist the OP with debugging support and advice.
On to function om. Again, terrible name. A function name should provide some hints as to what the function does.
Assumptions:
Om is intended to
- read in input to get the data required to fill out a boo structure
- place that boo structure into main's vector b
With that in mind,
- No need to return anything except perhaps an error code if the user fails to enter correct input.
- The only thing worth passing in is a reference to the vector. The reference allows the vector supplied by the caller to be modified.
If we knew what a boo was someone might be able to suggest better ways to do this and validate the user input.
void om(std::vector<boo> &bo)
{
boo temp; //start by making a temporary boo
std::cin >> temp.u; // read user input into the temporary boo
// removed the print out here
bo.push_back(temp); // copy the temporary boo into the vector
}
main is altered to remove unused string q and output the contents of vector b
int main()
{
std::vector<boo> b; // usual nagging about non-descriptive name
om(b);
for (boo testboo: b)
{ // print all boos in b
std::cout << testboo.u << std::endl;
}
}
And as one cut-n-paste-able block for trying it out and playing around:
#include <iostream>
#include <vector>
struct boo
{
std::string u;
int p;
};
void om(std::vector<boo> &bo)
{
boo temp; //start by making a temporary boo
std::cin >> temp.u; // read user input into the temporary boo
// removed the print out here
bo.push_back(temp); // copy the temporary boo into the vector
}
int main()
{
std::vector<boo> b; // usual nagging about non-descriptive name
om(b);
for (boo testboo: b)
{ // print all boos in b
std::cout << testboo.u << std::endl;
}
}