can the getline function be used with a string class object?
can the getline function be used with a string class object?
"In theory, there is no difference between theory and practice. But, in practice, there is."
- Jan L.A. van de Snepscheut
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; }
nextus, the samurai warrior
>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; }
My best code is written with the delete key.