I/O, strings and arrays combined

2012-03-15  Source: Original Site  Category:C++  Views:0 

Advertisement

guys and girls

I am currently new to C++ but I can say I was having fun learning it as a corresponding uni student in Australia until this assignment came across :(. There is a text file that contains in each line a city name (Sydney) and a distance ( 10 ) . In that file there are up no more than 100 cities. I need to read the text (ifstream inStream which i have done) and store the city names in one array and distance in another(IMPOSSIBLE for me ). We know that city name starts from 1-16 characters and 16 '' (eol) is the distance. Then the program will display the city array on cout.

Example:

Towns Available:
----------------
"Armidale"
"Tamworth"
"Murrurundi"
"Muswellbrook"
"Singleton"
"Mount Thorley"
"Paynes Crossing"
"Wollombi"
"Wisemans Ferry"
"Sydney"

Once all the cities have been displayed, cout to enter a starting point(city) and then to enter a destination. Here is a screen dump

Enter your starting point or 'exit' to stop: Singleton

Enter your destination or 'exit' to stop: Paynes Crossing

To get from "Singleton" to "Paynes Crossing":
------------------------------------------------
1. Singleton 0.00 km
2. Mount Thorley 10.69 km
3. Paynes Crossing 44.23 km
------------------------------------------------

example of test.txt file

Armidale 0
Tamworth 110.84
Murrurundi 201.40
Muswellbrook 266.77
Singleton 315.81
Mount Thorley 326.50
Paynes Crossing 360.04
Wollombi 368.94
Wisemans Ferry 450.15
Sydney 521.69

I dont care about my assignment marks (it dues tomorrow) but because i am a corresponding student I dont have anybody to ask all the questions so i will continue my course with gaps in parts of C++ which i dont want.

Sorry for the long thread but i need to explain this as much as possible. I have managed to read the file (ifstream) and by using istringstream to read the cities but cant store them in arrays.

Any help will be appreciated.

I can attach my code if required.

Related articles
  • I/O, strings and arrays combined 2012-03-15

    guys and girls I am currently new to C++ but I can say I was having fun learning it as a corresponding uni student in Australia until this assignment came across :(. There is a text file that contains in each line a city name (Sydney) and a distance

  • how to define strings and arrays ? 2013-10-17

    can someone pls help me ... i need to noe how to define strings and how to define arrays in C#.

  • string and arrays problem 2014-01-20

    I have a problem with sending array/string over the pages. my page "search.php" has the code: <FORM name action= "searchresult.php" method="post"> <SELECT name="column_name[]" MULTIPLE> <option value="field_a">a</option> <o

  • PHP String and array 2014-09-20

    How can I do something like this. $names = array("Mary", "Wendy", "Sam", "Jane"); if (in_array("Thiis is my long string to check and see if Jane has a name", $names)) { echo "Got It"; } I want to search for Key words in a long string and if it is pre

  • Please Help me with strings and arrays!!??! 2012-01-23

    I am new to this forum! Hopefully I can get some help with some basic programming stuff. Im a working on a project....Here are the requirements 1)Read in the file 2)Seperate the strings into 2 substrings and store them as arrays (Parrameters[x] and V

  • functions using strings and arrays 2012-03-01

    i'm writing a program to capture marks and names of 15 students and then i'll be using a function to display whether those students have failed,supplement or passed. but the problem is i'm using strings to capture those names and i'm using arrays to

  • Help with strings and arrays 2012-08-24

    My HTML knowledge is very small but I have no clue how to interpret this with the page that I am doing Each Question will have a static string that is the question text (prompt) and a form field (textarea/input/select-choice/checkbox/etc, as appropri

  • Comparing string and array values having used strtoupper 2015-02-13

    I'm trying to make a non-casesensitive comparison between a string value and an array value. I thought the best way to do this would be to use strtoupper to convert the string to capitals as all the values in the array are capital already. I'm using

  • Strings and Arrays (ez question) 2012-08-03

    How can I read a string into an array, much simillar in the way file($string); does when reading a file into an array. For example.. I want to have all the text in my post put into an array..how would I do that..?

  • HELP !!! STRINGS and ARRAYS 2013-08-19

    I have 7 randomly generated numbers stored in an array called ball. eg ball(1) = random number between 1 and 49 My problem is that i need all the numbers in the array to be unique. Can anyone help me please Dark : Dot

  • Strings and Arrays... Could someone please help? 2014-06-05

    I have an input file whos data needs to be entered into a one-dimentional array. The data file is as arranged as shown below. Each line is to be entered into a single array entry as a string. The code I have used so far (which doesn't work) to do thi

  • Ubuntu Bash Scripting Question: awk, strings, and arrays 2015-03-07

    Basically, I'm working with a string in this format: Subject: text Subject: more text Subject: even more text I want to populate an array (in a bash shell script) with data from the string, whose eventual elements, when working from the above example

  • Comparing string and array values !? 2015-03-31

    Trying to get this to work : <?php $lines = file('YourFile.txt'); $email = "[email protected]"; echo "email address = " .$email . "<br><br>"; foreach ($lines as $line_num => $line) { if ($email === $line) echo "MATCH"; print "<font

  • Removing duplicate values in String And array 2013-02-21

    If there is value some thing like this I need to remove duplicate values “TEST,ONE,TWO,TEST,ONE,THREE,THREE,FOUR”” I require above value as “TEST,ONE,TWO,THREE,FOUR” from a JavaScript function

  • Array/String intersect and Array/Array intersect code 2013-01-12

    got to thinking that i couldnt find a way to find the intersect of a string and array nor could i find a quick way to do an array / array. i searched a bit on google and didnt really find anything that showed me something like Array.Intersect(array a

  • How do you combine strings and ints? 2012-10-22

    How do you combine a string and an int in Python? For example, I was messing around with some of the winsound functions, and when I tried something like: print "Bitrate: " + params[1] Params[1] being the second element in the params array, which is c

  • C-strings and character arrays -- difference please? 2012-02-07

    What's the major differences between c-strings and an array of the type char? My book seems to say that they're different, but the same, but different... I know that both require me to include <cstring>. I know that I can use a few functions th

  • Convert an Array to String and back 2012-05-16

    i need your help. i want to convert an arry in an string and then back to an array. i think this must be possible, but how?! if the arry is something like this: $myvar[0]="value" $myvar[1][0]="value" $myvar[1][1]="value" $myvar[2]="value" i want to g

  • extracting sustrings from a string and store it in an array 2012-09-21

    Hi I want to extract sustrings from a string and want to store in an array. The string is dynamic it will change but the criteria to extract substring is same. say for example a string str="something is [!better] than [!nothing]" so i need to extract

  • Array required, but java.lang.String and java.util.Vector found 2013-02-21

    i'm trying to convert a C++ code about Hashtable in Java but i get these errors messages: - array required, but java.lang.String found & - array required, but java.util.Vector. Here is the C++ code first : #include "Hash.h" #include <cmath>