Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > Re: Dynamically...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 8 of 8 Topic 9582 of 9775
Post > Topic >>

Re: Dynamically read string

by Ulrich Eckhardt <doomster@[EMAIL PROTECTED] > May 9, 2008 at 09:27 AM

howa wrote:
> Are there any simple method to read string into dynamic array of
> string, e.g. char**

Using char** to hold strings is a bad idea, use std::vector<std::string>
unless you actually have a reason not to.

std::ifstream in("some text file");
std::string line;
while( getline( in, line))
   v.push_back(line);

> char **c;
> 
> Since the number of line is unknown, how the dynamic allocation is
> done actually?

You might want to take a look at realloc(), but as already mentioned,
don't
use manual memory management unless you really have a reason.

Uli


-- 
      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
 




 8 Posts in Topic:
Dynamically read string
howa <howachen@[EMAIL   2008-05-08 21:29:23 
Re: Dynamically read string
Marcin Swiderski <sfid  2008-05-09 09:15:18 
Re: Dynamically read string
Maciej Sobczak <see.my  2008-05-09 09:16:01 
Re: Dynamically read string
Oncaphillis <oncaphill  2008-05-09 09:24:35 
Re: Dynamically read string
Bob Lied <lied@[EMAIL   2008-05-09 09:28:53 
Re: Dynamically read string
"Jim Langston"   2008-05-09 09:22:45 
Re: Dynamically read string
"Martin T." <  2008-05-09 09:21:07 
Re: Dynamically read string
Ulrich Eckhardt <dooms  2008-05-09 09:27:41 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue Jul 8 23:48:38 CDT 2008.