Format in put text file

V

victor.herasme

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
 
S

Salt_Peter

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
 
J

Jorgen Grahn

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
 
J

Juha Nieminen

Salt_Peter said:
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.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top