Readin integers form *.txt file

B

boriss111

Hi,
How can I read interer number form the *.txt file? I have a matrix of
integer numbers stored in *.txt file, like this

3 7 7
12 12 10
14 7 8

and I have to read those numbers as numbers to use tham in some
calculations.
How can I do this?
Thank you wery much!!
 
M

mlimber

Hi,
How can I read interer number form the *.txt file? I have a matrix of
integer numbers stored in *.txt file, like this

3 7 7
12 12 10
14 7 8

and I have to read those numbers as numbers to use tham in some
calculations.
How can I do this?
Thank you wery much!!

Use std::ifstream to read them into a std::vector<int>. Depending on
how the matrices are stored in the file, you could read them in
different ways (for instance, the size might be fixed in advance; there
could be a header line telling you how many rows and columns there are;
it could be guaranteed that each row of the matrix is on one row in the
file, etc.). You'll find plenty of examples of using ifstream if you
search this group, so take a shot at it, and then ask more specific
questions if you get into trouble. One common problem is discussed in
this FAQ (just replace std::cin with your ifstream object):

http://www.parashift.com/c++-faq-lite/input-output.html#faq-15.5

Cheers! --M
 

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
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top