473,386 Members | 1,694 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,386 software developers and data experts.

how to read from a file and save some changes on it?

3
Hi
I'm doing a little c++ project. I have a notepad file and I would like to read each line into a separate array of integers.Suppose I have a text file that looks like this:

001-1 1/4
002-2 1/32
010-1 -1/1
011-2 -3/8
01-21 1/4
01-10 1/2
020-2 -1/8
02-20 1/16
02-1-1 -3/8
100-1 1/1
101-2 1/2
10-21 -1/1
110-2 1/4
11-1-1 1/2
12-2-1 1/3
12-1-2 1/6
1-22-1 -1/1
1-2-12 1/2
1-11-1 -1/1
1-12-2 -3/8
1-1-22 1/8
200-2 1/8
21-1-2 1/12
22-2-2 1/16
2-22-2 -1/8
2-11-2 1/4

I want to read every integer in a row and put it separately in another file in order to be readable by an array.
I would like to make an array that for instance for first line of this example the contents of array are:
x[0]=0 ,x[1]=0 , x[2]=1, x[3]=-1, x[4]=1, x[5]=4
in order to put into the array, I need to separate these integers.I want to know how to separate these numbers.

any help is really appreciated.
May 11 '11 #1
4 1933
weaknessforcats
9,208 Expert Mod 8TB
Just use any non-integer delimiter. Often a comma is used and these are the CSV (comma-separated values) files.
May 12 '11 #2
kassik
3
Thanks for your attention.
I have separate them in order to be readable and putting into an array, now i want to write a code to put every integer into array.
May 13 '11 #3
weaknessforcats
9,208 Expert Mod 8TB
You just did:

Expand|Select|Wrap|Line Numbers
  1. x[0]=0 ,x[1]=0 , x[2]=1, x[3]=-1, x[4]=1, x[5]=4
Since you are using C++ you can use the >> operator:

Expand|Select|Wrap|Line Numbers
  1. myfile >> x[0] >> comma >> x[1] >> comma etc...
so this data:

1234,567

will 1234 in x[0] and 567 into x[1]. The comma goes into a char junk variable. The comma tells the >> operator that the integer has ended.
May 13 '11 #4
kassik
3
thanks a lot.
it worked very well
Done.
///////////////////////////////////////////////////////////////////
May 20 '11 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: bbxrider | last post by:
running win2k adv server/ iis5.0 trying to setup on my web page where browsers can download a file, an .xls so been trying to figure out with a download 'link' what invokes the standard ms file...
2
by: Ilyas | last post by:
Hai, I'm new here. Sorry For typos. How can i open a file save dialog in a dotnet web app. (.aspx) to save my file at clients computer. Thanx. Greatings from Holland.
1
by: DFS | last post by:
I'm using a query as the SourceObject for a subform. When I change any of the column widths and try to close the form I'm prompted to save changes to the layout. Anyone know how to suppress...
8
by: Christopher Harrison | last post by:
I would like to, cleanly, watch a flat file for changes (updates and the like). The file will be altered by another program... I found some example code (which actually didn't compile) on Google,...
4
by: keithb | last post by:
How can an application change settings in the web.config file? I need to allow users to configure SMTP email settings with functionality similar to that provided developers by the ASP.NET Web Site...
0
by: Patty05 | last post by:
I have a datagrid on a form that update properly when form loads. When the program runs and I type in/add a new row in the datagrid, it does not save the changes. Any help would be greatly...
2
by: =?Utf-8?B?RGlvZ28gQWx2ZXMgLSBTb2Z0d2FyZSBEZXZlbG9w | last post by:
Greetings to you all I have a listbox with some data loaded from the database... When I select each record, it will fill a form that I have in the same window... What I wanted is that when...
2
by: xplode144 | last post by:
I have a Web application. i need to read a file once during the startup and preserve the read data throughout the life of the application. i will to access the data often during the page_load of...
11
by: gyap88 | last post by:
Hello i m using vb 2005 express to do my project. I m suppose to create a datagrid to allow user to make changes to the database. The program display the database in a datagrid where users can juz...
7
by: Andrew Jocelyn | last post by:
Hi I'm running an ASP.NET web application under IIS. I'm inserting a cache object with a file based CacheDependency. I've noticed that when the file changes the Cache object is not always...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...

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.