I was reading a C++ tutorial and the person writing it said to get a full line of text without stopping at the first space use getline(), I use visual c++ and it doesn't work. Is it a real function?
I was reading a C++ tutorial and the person writing it said to get a full line of text without stopping at the first space use getline(), I use visual c++ and it doesn't work. Is it a real function?
#include <iostream.h>
#include <string.h>
#include <iomanip.h>
using namespace std;
int main()
{
char name[40];
cout << "Enter your name: " << endl;
getline(cin,name);
cout << "Your name is: " << setw(3) << name;
return 0;
}
and anytime I try to use "namespace std" MSVC++ says std is not a type of namespace.
When using getline to read into a character array, it's an istream member function -
Code:#include <iostream> #include <iomanip> using namespace std; int main() { char name[40]; cout << "Enter your name: " << endl; cin.getline(name,40); cout << "Your name is: " << setw(3) << name; return 0; }
zen