Problem with getline

I tried to get in input a line with more than one word, and to do so i used the function getline(cin,text), but when I compile the program and run it, it skips the instruction getline
here's the code that doesn't work
Do anybody have a clue of what to do to fix it?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <string>
#include <iostream>
using namespace std;

string code   (string tx)
{
	 return (tx);
}

int main ()
{
     string ing;
	 getline(cin, ing);
         string=code(ing);
	 cout <<"code = " << ing;
	 getchar();
}
Last edited on
hmm, will that code compile?

string=code(ing);
string is a type so this shouldn't work. What happens if you just remove this line?
Tried that, but didn't work...
But I solved it anyway: here is missing a part of my code, so i tried to remove it from my actual code and found out that you can't put a cin before a getline
Thank you very much anyway :D
Topic archived. No new replies allowed.