C :: Storing File Data In A Structure Of Format Shown
Aug 5, 2014
I'm having trouble reading my data from a .txt file into a structure of the format shown in my code. I've made my student database in the program below based on user input and I didn't have a problem with that, but now it's come to input from a file it's making it difficult.
My three tasks are:
(1) A table containing 1 row per student, containing the student ID number and all of the student's marks.
(2) Another table, containing 1 row per student, containing the student ID number and the average mark obtained by that student.
(3) The average mark for each subject.
The assumptions to be made are: The student ID can begin with a zero, and should therefore be read in as a string.The test data will contain 20 students but the program should be able to deal with up to 100 students.Assume there are no more than 4 different subjects.
So based on the first assumption I've arranged the data in the file in an order in which the student ID begins with a zero:
...for twenty students, 80 lines of data. Now, on the assumption they must be read in as strings, this is what's making it tricky to store in the structure because, I've got 80 ID numbers but 20 repeat themselves 4 times. Once I've got this data in the structure below the tasks I won't have a problem with because I can just base it on a user input program but the data's already stored instead.
Below is my code for user input associated with task (1). In this example the IDs are stored as ints but for the file they will be strings. It compiles fine, displays the data as shown in the assignment sheet, but I don't know how to get the data into my structure. I can store the data in a structure of three arrays using fscanf() no problem, but it's not very "workable" for what I need to do with it.
struct Wine { string wineName; int vintage; int rating; double price; };
how can i store the file data below in an array with the structure type???
Dow Vintage Port ;2011;99;82 Mollydooker Shiraz Carnival of Love ;2012;95;75 Prats & Symington Douro Chryseia ;2011;97;55 Quinta do Vale Meão Douro ;2011;97;76 Leeuwin Chardonnay River Art Series ;2011;96;89
I have a multivalued function (created in some other software Mathematica) that looks like f[8.7,5.4]=4.8+8.7*I. In other words it's a complex valued function of two variables. I store the output of this function over a range of parameters in a text file that looks like:
Code:
f[1,2]=9.8+8.7I; f[4,5]=5.6-5.21I; . .
I could store it differently if that is easier, but essentially I just want some c++ code to read this in and store it, either in a vector type structure or Dictionary? (I don't think a double array will work as I don't know how long list of data is in advance).
I am trying to store the Title, Artist, and date published of a list of CD's. I can't seem to be able to get it to print the list or not sure if it is actually storing it. This is what i have so far.
#include <iostream> #include <fstream> #include <cstdlib> #include <string> using namespace std; int main() { char names[5][100];
And all of the above information is one person. As is "John,Peter,23" is first name, last name, age. When there are multiple people in a csv file how can i parse through and separate the information in a string and int for later use?
Im tasked with reading a data file, this is an example snippet
list of trophy winners year facup leaguecup 1stdiv 2ndiv 1960/61 Tottenham Hotspur Aston Villa Tottenham Hotspur Ipswich Town 1961/62 Tottenham Hotspur Norwich City Ipswich Town Liverpool 1962/63 Manchester Utd Birmingham City Everton Stoke City
The file starts in 1892 and is up to 2011/12, there is data missing for some years due to the wars etc,
once ive read the file, i need to store the data, for me to re-use.
There are a lot of useful link regarding reading data in, but they tend to be with very small files with say 10 lines of numbers.
I am trying to read a file use the data line by line to create into an object. The current file I have is like this and the code reading the file will be found below.
1223 Fake1 Name1 60 70 80 24 89 add1 Male 1224 Fake2 Name2 61 70 81 80 24 add2 Male 1225 Fake3 Name3 63 70 82 80 89 add3 Male 1226 Fake4 Name4 63 70 83 80 88 add4 Male
The problem I am having is that I need to put delimiters in the file so that a person can have more than one name and also the address can now hold multiple strings until the delimiter.
I would like to change my file to this;
1223 : Fake1 Name1 : 60 : 70 : 80 : 24 :89 : This will be address1 : Male 1224 : Fake2 Name2 : 61 : 70 : 81 : 80 :24 : This will be address2 : Male 1225 : Fake3 Name3 : 63 : 70 : 82 : 80 :89 : This will be address3 : Male 1226 : Fake4 Name4 : 63 : 70 : 83 : 80 :88 : This will be address4 : Male
How can I update the code below so that it can use the delimiters to create an object?
void loadFile(Person people[], int* i) { ifstream infile("people2.txt"); if ( !infile.is_open()) { // The file could not be opened cout << "Error";
typedef client...I would like to have these fields filled with this function below and stored in an array... Basically Multiple users and this is my function for it, if I can get it to work proper -.- .... I don't get syntax errors but I do get warnings
Code:
void getct(client *cl, int *pclientCounter) { char input[buff]; char *pinput = NULL; int typef = 0; int lengthf = 0; }
I want to display my data in rich-text box in the tree like structure,i fetch the data from the data base MSACCESS & i want to print it on my rich-textbox, what can i do ?
But the output rows are not aligned as shown in the attached picture. There a two problems.
1. Data rows don't align with the header row. 2. When the first element of a row changes to two digits, the other elements are shifted.
According to MSDN [URL] ...., CString::Format() works the same way as printf(). I wrote a small program using printf() to do the same thing, and the output in the console are perfectly aligned.
I then realized that the order that the second method gave me will make it very hard for me to calculate the RGBs. Because they will be calculated like wise..
P3 600 339 255 44 5 8 = sum 44 5 8 = sum 43 4 7 = sum 42 3 6 = sum
I have a file that can range from 100 rows to 10000+ that is comma delimited with 8 columns. The first 32 rows (also comma delimited) will always be ignored (geographical header information). I will be wanting the data from column2 and column3.
For this I believe I would need (2) For Loops as such:
I am trying to create a generic map container which shell contain data of different datatypes. I already found a solution in this forum here:
[URL]...
Introducing a container with a Base Class as content type and inserting objectes of Derived Class types from that Base Class suites my implementation very well. But it is not really working. I implemented it this way:
class MyType { public: MyType() {} virtual ~MyType() {} }; template <class PT> class ParseType : public MyType
[Code]...
Then I insert one element.
// index being an object of type Parser<string> ParseType<string>* test = new ParseType<string>( index ); // and index.val(0) = "-n" iMap.insert( pair< string, MyType* >( index.id(0), test ) );
Now I think I should be able to call
const string key("-n"); iMap.at(key)->content->val(n); Or iMap.at(key)->get_val(n);
But neither one compiles with the error that "class MyType" (as the map container is pointing to a MyClass object) has no member/member function "content"/"get_val".
I also tried introducing member and member function "content" and "get_val" in "class MyType", which I thought should be hidden while constructing ParseType<string>. This would compile but it does not call the member "content or member function "get_val" from class ParseType.
A second try was to remove templatization of "class ParseType" and introduce a specific, let's say, "class ParseString" for objects of type Parser<string>. But the problems remain the same either the compiler complains due to missing member/member function or retreiving the map content will not call the derived class member/member function.
I have a set of functions at work which are incredibly useful, however it only supports labels that come from a specific database because that database contains information on the type. I'd like to re-create it to make it more applicable to any member/static/global variables but don't know how to store the type.
I've already re-written it to an extent, but it only accepts int types. I'd like to template it to accept any type. The trick is storing that type so that the pointer can be dereferenced at a later time which I don't know how to do.
Interface:
typedef int T; // The goal is to remove this line! namespace TimerDelay { void SetAfterDelay ( T* lpLabelAddress, float delay, T target = T(1)); // Queues the set void ManageDelays ( float dt ); // sets the labels when appropriate }
Source:
#include <vector> namespace TimerDelay{ struct DelayObject { void* address; // I will probably need to add a container void* target; // to hold the type, but how can this be done?
[code]....
Edit:Is it possible to store a std::iterator_traits<> struct as a member of my structure? The g_list isn't templated as it needs to accept all types at the same time. That means that DelayObject cannot be templated. I think that means that I cannot use a templated member class as the size may be inconsistant.
I'm redesigning some code and I'm wondering what the best ways to store and access certain data is. The characteristics are as followed:
1) Based on data from a file, a distance matrix (N x N) is calculated. 2) Once the matrix is complete, the data will never change (unless a new file is read, but I can work around that by iteratively calling the problem with a new datafile on as command line parameter). 3) The data from the matrix is accessed billions of times from pretty much every other line of code.
In my old version, I had a class "Data" which a sub-class "Data::Distance" and I would put a reference in every other class that needed it. Now, my class hierarchy will be much flatter (basically all logic will be in one class; other classes will be POD structs).
Given the characteristics of the Distance table, is there a way to store them in a very efficiently-accessible way? Does it matter if it's stored in the main class where all the action happens in contrast to being a different class? Does making it static improve the performance? Casting it to const? Anything?
Again, the data is accessed billions of times so even minor differences can save a lot of time.
I have to store large amount of data and retrieve the same data then write into file in C++. Currently I am using vector to store and retrieve. But vector is taking more time to store and retrieve the element. Is any other best data structure to store and retrieve large amount of data in unordered way?
Following function is from a bank account, when new account is created it won't store it in the array or i guess it does but find_acct function wont be able to find it.
find_acct Function:
int findacct(int acctnum_array[], int num_accts, int requested_account) { for (int index = 0; index < num_accts; index++) if (acctnum_array[index] == requested_account) return index; return -1;
I am reading data from a text file into a program. I am well aware of the subtle distinctions in the mode of data input/entry when using the stream extraction operator, the get() function, and the getline() function.
My problem is that all of them do not read and/or store the newline character alongside the data read!
Any function that reads and stores data and the terminating newline character together??
I have almost a hundred names in a text file that I want to convert to email addresses and save to another file. I seem to have it working, but it doesn't print the full names in the email prefix. The output I'm looking for is Doe_John@livebrandm, but I'm only getting D_J@livebrandm. I'm not sure what I should specifically be reading up on that applies to this directly.
I am creating small application using c#.net.I removed all image tag using regular expression no I want to remove all video file and flash file also in source code of webpage.
so far I have tried this ...
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text;
I would like to modify the composition of this struct, so that I can create a special data structure by
vector<stest*> data_test; for(int i = 0; i < 10; i++) data_test.push_Back(new stest);
within this structure, I have: only one na and one nb, but ten groups of combination of va, vb, vc, vd that I can access by pointer, which means na, nb are independent but still inside of the structure.
I'm currently having the following data structure:
typedef struct { int a; int b; } S; <vector <vector<S> > v;
Now I also have different pointers that can be set in connection with one instance of the above shown vector. Therefore I was attempting to work with a map:
map<p*, <vector<vector <S> >, vector<sI> > m;
However, it seems like it doesn't work that way. Therefore I tried the following:
I want to know this because if I happen to want to use a lot of insertions and deletions then it is more efficient to make use of Linked List instead of Dynamic Array.
While, if I happen to want to just access random parts of the Array, then Dynamic would be more efficient.
I want to make a 2D game using SDL engine and I need to check whether or not an object is colliding with a list of other objects. (because there would be more then one objects on the map.)
Since I would simply be accessing each object sequentially to check whether or not the object is colliding with another the object in question, and since any of those objects could "die" and be deleted at any time, it makes more sense to use Linked List then a Dynamic Array.