473,396 Members | 1,924 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.

Writing an array and calling the array question

Hello, I am a newbie to C++. I read C++ Primer from cover to cover at least 3 times, but that did not help. I am trying to write a program that loads txt file and write the data into array. the data looks as follows:

01/02/2004,1108.48
01/05/2004,1122.22

I managed to write program that loads the data, but I am not so sure about writing them into array. I want to 1) open the file to input (which I wrote the codes for), 2) read the file into a string (which I have absoltely no idea how to) 3) then split the string into an array of Month, Day, Year, and Price.

Another question is: If I build a function that needs to call on the array, how do I do so? Is it Somfunction (&array[1], &array[2], etc)?

Any help would be appreciate it, but if you could provide as much detail as possible, it would be great. thanks:)
Sep 25 '07 #1
3 1313
sicarie
4,677 Expert Mod 4TB
I would recommend using getline() in a loop to get each line, and then you can store the line into the array. If you check out that link, it has some good code examples, but post again if you get confused.

::Edit:: Cplusplus.com also has a very good tutorial on accessing arrays.
Sep 25 '07 #2
I would recommend using getline() in a loop to get each line, and then you can store the line into the array. If you check out that link, it has some good code examples, but post again if you get confused.

::Edit:: Cplusplus.com also has a very good tutorial on accessing arrays.
thanks for the info:) But what do you mean by using getline() in loop? how does it work? If I use "while" statement, can I use *.eof()?
Sep 26 '07 #3
sicarie
4,677 Expert Mod 4TB
thanks for the info:) But what do you mean by using getline() in loop? how does it work? If I use "while" statement, can I use *.eof()?
Yep, you can. (And the link is the getline() documentation with examples to help you figure out how getline() works).
Sep 26 '07 #4

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

Similar topics

35
by: VK | last post by:
Whatever you wanted to know about it but always were affraid to ask. <http://www.geocities.com/schools_ring/ArrayAndHash.html>
15
by: Douglas Garstang | last post by:
All, I posted a newsgroup question here a few weeks back, asking some questions that related to my 10 year quest (so far) to understand pointers. Someone suggested I write a simple emulator....
4
by: songkv | last post by:
Hi, I am trying to reassign an array of char to a string literal by calling a function. In the function I use pointer-to-pointer since I want to reassign the "string array pointer" to the string...
16
by: Ali | last post by:
Hi I want to write (or read) to a stream, but the data is not byte array I converted the data to byte array manually, but it is very slow, (becuse the data is very large) Is another way for this...
7
by: heddy | last post by:
I have an array of objects. When I use Array.Resize<T>(ref Object,int Newsize); and the newsize is smaller then what the array was previously, are the resources allocated to the objects that are...
12
by: Martien van Wanrooij | last post by:
I have been using for a while a class to create photo albums. Shortly, an array of photo's is declared, initially they are shown as thumbnails, by clicking on a thumbnail a larger photo is shown...
4
by: drktmplr11 | last post by:
Hi, this is my first post here at the forums, and I am looking for assistance with what looks to be a syntax error within my code. I am attending FIU, and looking to broaden my understanding of...
10
by: Phillip Taylor | last post by:
Hi guys, I'm looking to develop a simple web service in VB.NET but I'm having some trivial issues. In Visual Studio I create a web services project and change the asmx.vb file to this: Imports...
4
by: mab464 | last post by:
I have this code on my WAMP server running on my XP machine if ( isset( $_POST ) ) { for($i=0; $i<count($_POST);$i++) { if ($ans != NULL ) $ans .= ", " . $_POST ; // Not the first...
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: 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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.