delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/12/23/21:19:21

From: "Tom" <thomasbd AT erols DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Pointers, chars, and strings...
Date: Thu, 23 Dec 1999 21:10:31 -0500
Lines: 33
Message-ID: <83ujjn$riu$1@bob.news.rcn.net>
X-Trace: ayMJeiFSipMRv7SvXDyhyIo+C5Lo2y8TpasGXf5Z6Jtus76OgSmBrQ==
X-Complaints-To: abuse AT rcn DOT com
NNTP-Posting-Date: 24 Dec 1999 01:51:51 GMT
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6600
X-Newsreader: Microsoft Outlook Express 5.00.2919.6600
X-MSMail-Priority: Normal
X-Priority: 3
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

I am using a library which reads a line of a file and edits the text.  The
only problem is that the type of input it takes is a char with a pointer.
What I am trying to try do is open up a text file, and send that line in the
char * form.  I have tried the following:

__________________________________
#include <fstream.h>
#include <iostream.h>

char s;
ifstream fin("file.txt");
while (fin.get(s))
cout << s;
__________________________________

                                and
__________________________________
#include <string.h>
#include <fstream.h>
#include <iostream.h>

string s;
ifstream inputfile("file.txt");
while (getline(inputfile, s) )
cout << s;
__________________________________

One of these is a string and the other is a plain character.  I'm pretty new
at this and I don't understand pointers well.  If possible I would like to
be able to call each line by doing a s[int] with int being the line of the
file.  Thanks.  Any help is greatly appreciated.


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019