cin.getline()

I'm having trouble with this:

1
2
3
4
5
for(int i = 0; i < n; i++)
	{
	cout << "Enter the name of student " << (i + 1) << std::endl;
	cin.getline(pa,n);
	}


To be more precise, it's this
 
cin.getline(pa,n);


Apparently there aren't enough arguments, is there any way to get this to work?

If any more code is needed, I will give it to you.
Last edited on
plz elaborate your problm
closed account (zb0S216C)
Assuming pa is of type char[], that call should be fine. According to this site's reference, all arguments are accounted for.

Hmmm...

Wazzak
Framework, you have it right and I thought the same thing too.
But, when I put my mouse over the red squiggly line on the ., the error message is:


Error: No instance of overloaded function "std::basic_istream<_Elem,_Traits>::getline[with_Elem=char,_Traits=std::char_traits<char>]" matches the argument list


And with the closing brace, it reports:


Error: too few arguments in function call


Does anyone know of the reason it may be doing this?
not sure if this helps


Using cin.getline

The getline member function is similar to the get function. Both functions allow a third argument that specifies the terminating character for input. The default value is the newline character. Both functions reserve one character for the required terminating character. However, get leaves the terminating character in the stream and getline removes the terminating character.

The following example specifies a terminating character for the input stream:

#include <iostream.h>

void main()
{
char line[100];
cout << " Type a line terminated by 't'" << endl;
cin.getline( line, 100, 't' );
cout << line;
}


Maybe just use cin.get? Maybe your compiler is requiring a terminating character.

-BHill
Using cin.get() does help me with the finishing brace - so thank you for that - but the first error is still there; that is:


Error: No instance of overloaded function "std::basic_istream<_Elem,_Traits>::getline[with_Elem=char,_Traits=std::char_traits<char>]" matches the argument list
Last edited on
Did you try giving it a 3rd argument as a terminating character just to see if the error goes away?

-BHill
Maybe it needs to be:
 
std::cin.getline(pa,n);


I don't really know, but it's something to try.
I've tried all of that, but still I'm doing something wrong.

This is really getting annoying.
closed account (zb0S216C)
If you're using VC++, try rescanning the project. That will force Intellisense to relocate all used symbols, functions, etc.

Wazzak
Last edited on
Here:
Hope it this helps ;)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>

using namespace std;

#define n 7 

int main(){
    
    char pa[n];


for(int i = 0; i < n; i++)
	{
	cout << "Enter the name of student " << i <<
     endl;
	cin.getline(pa,n);
	}
	
	system("PAUSE");
	return 0;
}
Topic archived. No new replies allowed.