bo*******@yahoo.com wrote:
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-lit....html#faq-15.5
Cheers! --M