I'm half a beginner of c++ programming. I just want to try out getline function but there're errors and i don't know what causes the error. The testing code is very simple. I included <iostream>, <string>. And I am using netbeans on Mac.
Here is the error description:
main.cpp:15:5: error: no matching function for call to 'getline'
getline(a,b);
^~~~~~~
/Library/Developer/CommandLineTools/usr/bin/../lib/c++/v1/istream:1633:1: note: candidate template ignored: could not match 'basic_istream<type-parameter-0-0, type-parameter-0-1>' against 'char [40]'
getline(basic_istream<_CharT, _Traits>& __is,
^
/Library/Developer/CommandLineTools/usr/bin/../lib/c++/v1/istream:1584:1: note: candidate function template not viable: requires 3 arguments, but 2 were provided
getline(basic_istream<_CharT, _Traits>& __is,
^
/usr/include/stdio.h:440:9: note: candidate function not viable: requires 3 arguments, but 2 were provided
ssize_t getline(char ** __restrict, size_t * __restrict, FILE * __restrict) __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_4_3);
1 2 3 4 5 6 7 8 9 10 11
|
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
char a[40],b[40];
getline(a,b);
cout<<b;
return 0;
}
|
I know I can use strcpy, but i just want to test getline function. Is there something wrong with my code? or the library?