473,396 Members | 2,030 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Readin integers form *.txt file

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!!

Aug 13 '06 #1
1 1608
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

Aug 13 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Thomas | last post by:
What's the quickest way to write and read 10.000 integer values ( or more ) to and from a file? Using struct somehow? The example in the docs shows how to handle to or three arguments, but is the...
35
by: Durgesh Sharma | last post by:
I want to use strrchar(source_string,last_char ) function from string.h header file,to find out the last occurrence of the NON SPACE Alphanumeric Character. Then i will put a NULL CHAR after...
13
by: Rick | last post by:
The following code will enter an infinate loop when in ReadChars. I can only make it happen when reading a Stream and with this particular XML. If I use the ReadInnerXml call rather than my own...
2
by: Marc | last post by:
So i have a text file where each line represents a button name. What the code I need to read this file and creatre a new button from each line.. so far I just have code to read the whole...
1
by: belley | last post by:
I have this simple file: ********* <?xml version="1.0" encoding="ISO-8859-1"?> <books:names xmlns:books="http://www.w3.org/1999/xlink"> <book:name xmlns:book="http://www.w3.org/1999/xlink"...
1
by: Poto | last post by:
Hello: i need to read a file line by line because there is diferent information in each line that i need to take out separatly, i'm using the while construction like this while ($file = <FILE>){...
11
by: Victor Lagerkvist | last post by:
Greetings, I know it's usually a bad habit to include several questions in a single message, but they are quite related. I have declared and defined a function named readin, whose purpose is to...
4
by: thaiZilla | last post by:
How do i read a file permission? i know that ls -l *filename* will list all information about the file including file permissions eg -rwxr-xr-x 1 norman.thai users 187 Jan 15 10:33 firstline... ...
7
by: vinay3744 | last post by:
Hello I am particularly new to programming working on a mathematical analysis where I have to perform some functions on a text file. I have a text file in this format, it contains 3 numbers in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.