From: Thomas Demmer Newsgroups: comp.os.msdos.djgpp Subject: Re: Input/Output Date: Thu, 01 Jan 1998 15:35:46 +0100 Organization: Lehrstuhl fuer Stroemungsmechanik Lines: 74 Message-ID: <34ABA9C2.A626FD14@LSTM.Ruhr-UNI-Bochum.De> References: <01bd1616$a61f4280$7afd64c3 AT win95 DOT algonet DOT se> NNTP-Posting-Host: bvb.lstm.ruhr-uni-bochum.de Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Content-Transfer-Encoding: 8bit Precedence: bulk Erik wrote: > > Hello! > > I have a question about Input and Output in C++. I was trying to make a > program that asks for a string. > > This is how far I got: > > #include > > int main() > { > char txt; > > cout << "Print a string: " << endl; > > So far I´ve got variable of the type CHAR called "txt". In txt should that > you write be stored. > > Then the program will ask me to write something. > Here is my problem. How should I store that write in the variable "txt"? > > Please someone help me!! Simple answer: cin >> txt; Longer answer: This will under most circumstances not get you what you want. txt is a char, 1 letter. So you probably want something like char txt[256]; cout << "Say something: "<> txt; This will skip all white space and get you all characters up to and not including trailing white space. If you want the whole line, use cin.getline(txt,256); // Might be (256,txt)! Even longer answer: say info iostream on the command line, read it. -- Ciao Tom ************************************************************* * Thomas Demmer * * Lehrstuhl fuer Stroemungsmechanik * * Ruhr-Uni-Bochum * * Universitaetsstr. 150 * * D-44780 Bochum * * Tel: +49 234 700 6434 * * Fax: +49 234 709 4162 * * http://www.lstm.ruhr-uni-bochum.de/~demmer * *************************************************************