strings

there are five different methods to input a string.....can any one share all plz
Hmm...
fgets
cin >>
cin.getline
and maybe others if you want a string with newlines in it.
Sounds like a question from a homeworking assignment or quiz...
closed account (3pj6b7Xj)
I know of the following...

#include <string>
#include <sstream>
#include <fstream>

others i've never used are..

#include <istream>
#include <ostream>

However, istream & ostream are a combination of iostream, so I have used them but not specifically one single implementation.

fstream is for reading files if I remember, sstream is a console type of stream, i'll give an example...

1
2
3
4
5
int number = 2398; // (int) number 2398
stringstream datastring; // create string stream object
datastring << number; // flow number into datastring
string numberstr; // create string object
datastring >> numberstr; // flow data from datastring into string numberstr 


The above code basically converts an Int to a string type or in other words, the integer value 2398 will become a string.

There are some others in if you look hard enough. I am afraid I may have answered your question. I really do consider beginners to stop by a book store and a get a book on C++ it is what I did......even better.....amazon sells the kindle a wonderful reading device you can use to purchase an ebook and learn C++ reading from the kindle while being next to your computer.......that sounded like advertising but its not, just some advice.
Topic archived. No new replies allowed.