I am having problems with reading a file into an array.
This is my code.
![1 E/7 Programming Assignment 6.cpp Defines the entry point for the console application. 2 #include #include #include #include stdafx.h string iostream fstream 6 7 8 9 10 using namespace std; //read and store data into two arrays 12 Ebool GetBowlingData(string fileName, string nameArray[]) fstream myfile; 14 15 16 17 18 19 20 21 : myfile.open(fileName); ?: if (!myfile . fail()) : //loop until the last line of the file : : while (!myfile . eof()) 1//populate the arrays from the fil 23 24 25 26 27 28 29 30 int n 0; myfile nameArray[n :return true; return false](http://img.homeworklib.com/questions/b32fb030-ba6f-11eb-9e0c-6f0c0f58dfb5.png?x-oss-process=image/resize,w_560)

This is what I get when I run my program.

But this is my text file I am reading.

I tried everything and it seems to be reading in the last digit of the file. I want to read in their names line by line into an array and ultimatly also read in the scores line by line.
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int n=0;
bool GetBowlingData(string filename,string nameArray[])
{
fstream file;
file.open(filename);
if(!file.fail())
{
while(!file.eof())
{
file>>nameArray[n];
n++;
}
return true;
}
return false;
}
int main()
{
string fileBowlingScores,bowlersNames[20];
int bowlersScore[20],averageScore[20];
cout<<"Please"<<endl;
cin>>fileBowlingScores;
GetBowlingData(fileBowlingScores,bowlersNames);
for(int i=0;i<n;i++)
{
cout<<bowlersNames[i]<<endl;
}
return 0;
}
This will get each and every word in the file(even the numbers are considered as a word as it is a text file) into the array yiou provided. Now you will have to change the change the string into numbers. I didnt know how you want that as a 1d array or 2d array. Make sure you give all the necessary details in your next question.
I am having problems with reading a file into an array. This is my code. This...
I am having trouble trying to output my file Lab13.txt. It will
say that everything is correct but won't output what is in the
file. Please Help
Write a program that will input data from the file
Lab13.txt(downloadable
file);
a name, telephone number, and email
address.
Store the data in a simple local array to the main
module, then sort the array by the names. You should have several
functions that pass data by reference.
Hint: make your array large...
I am reading a text file and trying to store the information into an array so I can use this in different parts of my program. So a dynamic array. So far I have been able to retrieve the information from the text file and organize it by category (User name,User ID, User password) I am having troubles allocating an array and storing the information correctly. Since I have different data types (int, string) do I need to create a...
I am having a little trouble with my Python3 code today, I am
not sure what I am doing wrong. Here are the instructions:
and here is my code:
update: I have seen I did not close x in sumFile and I am still
only getting a 2/10 on the grader. any help appreciated.
Lab-8 For today's lab you going to write six functions. Each function will perform reading and/or write to a file Note: In zybooks much like on...
Hi I was hoping to get some help with my code for this problem. I don't know how to correctly read a txt file and the difference between using string and cstring. My code is at the bottom please help thanks. 1. Create the following “data.txt” file. Each record consists of customer's name and their balance: Maria Brown 2100.90 Jeffrey Jackson 200.20 Bernard Smith 223.10 Matthew Davenport 1630.20 Kimberly Macias 19100.90 Amber Daniels 2400.40 The records in the file will...
The input file is already there. the file is too long, don't
have to send it.
using virtualbox ubuntu
We want to create a command line terminal where user can run the
snap commands with three different options: -thanos, -ironman and
-holk. The terminal must keep listening to user command.
If the user type:
snap -thanos: all the text line in the text file “input.txt”
that does not contain the word “thanos” must be randomly removed.
The remaining text...
can you please split this program into .h and .cpp file #include <iostream> #include<string> #include<fstream> #define SIZE 100 using namespace std; //declare struct struct word_block { std::string word; int count; }; int getIndex(word_block arr[], int n, string s); int main(int argc, char **argv) { string filename="input.txt"; //declare array of struct word_block word_block arr[SIZE]; int count = 0; if (argc < 2) { cout << "Usage: " << argv[0] << "...
So my test.h file has: #include <iostream> #include <fstream> using namespace std; class test { private: int data[]; public: test(string filename); }; My test.cpp file has: #include "sort.h" test::test(string filename) { ifstream inFile; inFile.open(filename); int iter = 0; while(!inFile.eof()) { cin >> data[iter]; iter++; } int numberOfNumbers = iter; for (iter = 0; iter < numberOfNumbers; iter++) cout << data[iter] << " "; ...
Need to check if File is successfully opened? C++ It works when I input the right txt file. But, it keeps stating, File successfully open." even I put in a non-existing file. Here are the specifications: Develop a functional flowchart and then write a C++ program to solve the following problem. Create a text file named first.txt and write your first name in the file. You will be reading the name of the file from the keyboard as a string,...
C++ problem. hi heys, i am trying to remove beginning and the end whitespace in one file, and output the result to another file. But i am confused about how to remove whitespace. i need to make a function to do it. It should use string, anyone can help me ? here is my code. #include <iostream> #include <iomanip> #include <cstdlib> #include <fstream> using namespace std; void IsFileName(string filename); int main(int argc, char const *argv[]) { string inputfileName = argv[1];...
You will be reading in 3 files in the program. One will contain a list of 1000 words in unsorted order. The second file will contain 1000 words in sorted order. The final file will contain 20 words to be searched for. The main program has been written for you. You will be implementing three functions: bool readWords(string array[], int size, string fileName); int linearSearch(string wordToFind, const string words[], int size); int binarySearch(string wordToFind, const string words[], int size); The...