Hi!

I'm working on a project and need a way to add a newline to the input stream, by code and not by user's help.

The user should not need to do anything, I need a simple line of code that places a newline in the input stream, but I don't know how.

I meen like cin.get(), but without the user need to press a key.


Can anybody help?

Not really.

I've used cin.get() in a function, which is called several times during a full program run. After the first run of this function cin.get() is discarded somehow.
But after that, the user will have to press a key, and I don't want that.

Well, if you don't want the user to press a key then delete the cin.get() lines -- that's what that function is used for.

>>cin.get() is discarded somehow.
Probably because a previous cin operation was for an integer, which leaves the '\n' in the keyboard buffer, and the next cin.get() will remove that '\n' from the keyboard buffer and toss it away.

int num;
cout << "Enter a number\n";
cin >> num;
cin.ignore(); // flush the '\n' from keyboard buffer

Thanks!

If you don't mind, I have another question.

I have a function that has a vector<vector<int> > return type.
Later I call this function from another function, which shall declare a new variable and copie the last function's return value.

Ex.

vector<vector<int> > f (...) {
...
}

void g (f() ) {
vector<vector<int> > x = f();
...
}

But this will cause a out of range error, but I can't fix it.

Please help!

make it a reference parameter, not a return value

void f(vector<vector<int>> & ay)
{
   // fill in the vector
}

int main()
{
    vector<vector<int>> ay;
    f( ay );
}
This question has already been answered. Start a new discussion instead.