From: sproctor AT enter DOT net (Sean) Newsgroups: comp.os.msdos.djgpp Subject: Re: Newbie Question - Convert string to numerical value Date: Sat, 04 Sep 1999 04:37:00 GMT Message-ID: <37d39de7.4581168@news.enter.net> References: <37d32cc7 DOT 4183133 AT news DOT inet DOT tele DOT dk> X-Newsreader: Forte Agent 1.5/32.452 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 207.16.153.74 X-Original-NNTP-Posting-Host: 207.16.153.74 X-Trace: 4 Sep 1999 00:37:21 -0400, 207.16.153.74 Organization: Enter.Net Lines: 40 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com n DOT o DOT s DOT p DOT a DOT m DOT thygesens AT post DOT tele DOT dk (Lasse Krogh Thygesen) wrote: >c++ related newbie question. > >I need to convert a string which contain a number to a numerical >value. Can anyone tell me which include file and command to use. > >The string I need to convert is filled with value coming from a text >file on the disk. The file is opened and a value is read with the word >operator (?) into the string. The value should be an integer, but the >word operator won't read the string into an integer. > >Is this nonsense ? > >--- [www.lkt.person.dk] --- [www.maverick.subnet.dk] --- I don't really understand what you meant, but I'll just say what I think your answer is. (I didn't know there was a word operator) use atoi() it's in stdlib.h untested example #include #include int main() { char str[50]; int num; cout << "Enter your number: "; cin >> str; num = atoi(str); cout << "\nYour number is " << num; return 0; } That should work. Sean