Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Format in put text file

Reply
Thread Tools

Format in put text file

 
 
victor.herasme@gmail.com
Guest
Posts: n/a
 
      08-30-2008
Hi,

I hava an input file structured like this:

X XYData-1

1. 3.08333
2. 9.05526
3. 3.13581
.......

X XYData-2

1. 4.08322
2. 4.02526
3. 3.95891
...............

i want to format it so i only get the second column, in order to place
it in a mxn matrix. Let's say i want this:

number1 number2 number3..NumberN
number4 number5 number6
.................................................. .........

number1 number2 number3..NumberN

i am trying to use GETLINE to input numbers in the second column and
IGNORE in order to omit the X etc. Yet i need a little help on how to
size the array if i do not know how large it will be in advance. Can
anyone ehlp me with this? Thanks,

Victor
 
Reply With Quote
 
 
 
 
Salt_Peter
Guest
Posts: n/a
 
      08-30-2008
On Aug 30, 1:12 pm, "victor.hera...@gmail.com"
<victor.hera...@gmail.com> wrote:
> Hi,
>
> I hava an input file structured like this:
>
> X XYData-1
>
> 1. 3.08333
> 2. 9.05526
> 3. 3.13581
> .......
>
> X XYData-2
>
> 1. 4.08322
> 2. 4.02526
> 3. 3.95891
> ...............
>
> i want to format it so i only get the second column, in order to place
> it in a mxn matrix. Let's say i want this:
>
> number1 number2 number3..NumberN
> number4 number5 number6
> .................................................. ........
>
> number1 number2 number3..NumberN
>
> i am trying to use GETLINE to input numbers in the second column and
> IGNORE in order to omit the X etc. Yet i need a little help on how to
> size the array if i do not know how large it will be in advance. Can
> anyone ehlp me with this? Thanks,
>
> Victor



Arrays are prehistoric, consider std::vector.
You'll rarely ever use an array again.
The std::vector is a sequenced container which is dynamic and holds
elements in contiguous memory.
The only requirement is that the type stored be copyable and
assigneable.

see http://www.sgi.com/tech/stl/Vector.html
 
Reply With Quote
 
 
 
 
Jorgen Grahn
Guest
Posts: n/a
 
      09-08-2008
On Sat, 30 Aug 2008 10:23:14 -0700 (PDT), Salt_Peter <> wrote:
> On Aug 30, 1:12 pm, "victor.hera...@gmail.com"
> <victor.hera...@gmail.com> wrote:
>> Hi,
>>
>> I hava an input file structured like this:

....
>> i am trying to use GETLINE to input numbers in the second column and
>> IGNORE in order to omit the X etc. Yet i need a little help on how to
>> size the array if i do not know how large it will be in advance. Can
>> anyone ehlp me with this? Thanks,
>>
>> Victor

>
>
> Arrays are prehistoric, consider std::vector.
> You'll rarely ever use an array again.


Actually, I think he wants std::string, to read a line of text into.

std::getline(std::istream&, std::string&)

I couldn't understand the formulation of the problem, but it seems
like a traditional one-line-in, one-line-out filter, so there's
nothing to store.

/Jorgen

--
// Jorgen Grahn <grahn@ Ph'nglui mglw'nafh Cthulhu
\X/ snipabacken.se> R'lyeh wgah'nagl fhtagn!
 
Reply With Quote
 
Juha Nieminen
Guest
Posts: n/a
 
      09-08-2008
Salt_Peter wrote:
> Arrays are prehistoric, consider std::vector.
> You'll rarely ever use an array again.


std::vector has its disadvantages, though.

For example, if you have a pointer to an element, and then you add new
elements to the vector, your pointer might get invalidated (or not,
there's no way of knowing). Also the memory usage of std::vector might
not alway be optimal, especially if you are constantly adding new
individual elements to it.

In this respect std::deque is better: Adding elements (at the
beginning or the end) doesn't invalidate pointers pointing to existing
elements, and the memory usage is often better in the latter situation.
(OTOH the memory is not contiguous.)
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
why does the following with Queue, q.put('\x02', True) not put itin the queue? Gabriel Rossetti Python 3 04-25-2008 03:41 PM
Open Document Format / Rich Text Format Editor in Java Dominik Java 4 03-22-2007 01:55 PM
Splitting a multirecord per file format to a single record per file format: Right approach? Randy Kramer Ruby 2 01-12-2007 06:46 PM
How to Put Both Left-Justified Text and Right-Justified Text on the Same Line? jaykchan@hotmail.com HTML 5 06-29-2005 07:01 PM
How can you put text from a file into a textarea box, when the file is selected from a Select list! Shaiboy_UK ASP General 11 12-22-2004 07:46 AM



Advertisments