delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/10/04/18:28:22

From: "Tom" <thomasbd AT erols DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Convert from basic_string to char *...
Date: Mon, 4 Oct 1999 17:39:09 -0400
Lines: 41
Message-ID: <7tb6c9$770$1@autumn.news.rcn.net>
X-Trace: LNiGouLFvIQ5hSoMsJj34tlSUJfLKW3sgru4JZuLjxrGRqatzVf8Rg==
X-Complaints-To: abuse AT rcn DOT com
NNTP-Posting-Date: 4 Oct 1999 21:31:53 GMT
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300
X-Newsreader: Microsoft Outlook Express 5.00.2314.1300
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

Is it possible to convert a string that was obtained using getline into a
char *?  I know how to convert regular strings to char * but when I try a
line obtained from getline it says it can't convert basic_string to char *.

_________________________
int main()
{
char *test1 = "hello";
string test2= "hi";

cout << test1 << endl;
cout << test2 << endl;

test1 = test2;

cout << test1;
return 0;
}
_______________________________

The above program works.  I want to do the following without errors.

int main()
{
string s;
char *b[500];
int n = 0;

ifstream inputfile("text.txt");
while ( getline( inputfile, s) )
{
b[++n] = s;
cout << b[n] << endl;
}
return 0;
}
___________________

Is this possbile?  Thanks.


- Raw text -


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