can the getline function be used with a string class object?
Printable View
can the getline function be used with a string class object?
if you are speaking of a string.h file and you declare a string as String aString..then at school we used this..but i dont like it....
that only works for some...i have never really implemented any strings in any of my code..i always think of them as array of characters likeCode:#include <lvp\string.h>
#include <iostream>
using namespace std;
int main()
{
String something;
getline(cin, something);
return 0;
}
Code:#include <iostream>
using namespace std;
int main()
{
char* something = new char[100];
cin.getline(something, 100, '\n');
delete [] something;
return 0;
}
>can the getline function be used with a string class object?
Yes, getline for std::string's is implemented in <string>:
-PreludeCode:#include <iostream>
#include <string>
int main()
{
std::string s;
if ( std::getline ( std::cin, s ) )
std::cout<< s <<std::endl;
}