C++ :: Reading Info From A File And Put Data Into Vectors Of Its Appropriate Type

Apr 4, 2013

I'm trying to read information from a file and put the data into vectors of its appropriate type. For example: the file will have an int ID, string firstname, string lastname, double salary, int hours_per_week, and string work_position. All this data is separated by ";". I don't know how to read this file into the appropriate vectors: vector<int> ID, vector<string> fname, vector<string> lname, vector<double> salary, vector<int> hpw, vector<string> work.

View 8 Replies


ADVERTISEMENT

C++ :: Reading Data From A File And Put It Into Several Vectors

Sep 26, 2013

I need debugging the code provided below, which reads data from a file and puts it into several vectors.

Something very strange happens: if I try to read the file up to the last line, I get an runtime error, while if I try to read the file up to the second last line, I do not get the error.

However, if I try to read the file up to the last line, it READS IT CORRECTLY, as you can see that it prints out the right values.

Following there is the code and the file that I am trying to read.

Code:

#include<stdio.h>
#include<iostream>
#include<fstream>
#include<vector>
#include<set>
#include<queue>
#include<cmath>
int main() {
std::ifstream fp;

[Code] ....

Following, there is the file "link1.dat" that I am trying to open.

10
1 1 8 2.171563e-06 1.837725e-02 3.939158e-05
2 3 17 1.067390e-05 3.612572e-02 1.047469e-04
3 2 9 1.166078e-05 3.280536e-02 3.207107e-05
4 4 26 1.236551e-05 3.143551e-02 2.054519e-04
5 7 18 3.430566e-05 2.821557e-02 1.109601e-04
6 12 18 9.582478e-06 2.847688e-02 4.161835e-04
7 12 43 5.816782e-06 4.352799e-02 4.141623e-04
8 12 16 2.036719e-05 4.194844e-02 2.629832e-04
9 12 11 1.829523e-05 3.096140e-02 4.543953e-04
10 11 47 2.563568e-05 4.001301e-02 3.140850e-04

View 5 Replies View Related

C++ :: File Writing - Input Your Login Info And Program Writes That Info To A Text File

Jan 30, 2013

I'm trying to make a program that you input your login info and it writes that info to a text file. Then, later on once I get my problem fixed, the program will read the info to the user. my code is as follows(the input part is a bit lengthy):

// Password Log
#include <iostream.h>
#include <fstream.h>
#include <string>
#include <time.h>
using namespace std;
ofstream login;

[Code] ....

What my problem is when I choose "Input new login info" it automatically inputs I have no clue, and calls next program.

View 3 Replies View Related

C++ :: How To Access Excel File From A Program - Search It For Data And Return Info

Nov 12, 2014

I have been asked to create a program that accesses an inventory file done in excel, look for a alpha-numeric code, which will be inputed by the user, and return to the user informations related to the position of that code, and informations related to the header of the column in which the code resides.

An example of the function I need the program to perform would be:

User inputs: 1429-R1

And the program returns: Marco's 6A, 8/21/2014, 3/7/2014.

using the following example of file:

Marco's 6A
Assessment 8/21/14 3/7/14
1584-R1 1584-R1 1584-R1
1461-2R1 1461-2R1 1461-2R1
1429-R1 1429-R1 1429-R1

View 1 Replies View Related

C :: Error To Define Data Type File?

Mar 21, 2013

I program unix sokcet programming , and part of my code is ti open file from server and open it , but i surprised with this wierd error i dont have any reason for it ?

Code:
#include <errno.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>

[Code] ....

File name is : myHeader.h
myHeader.h:24:1: error: unknown type name "File"???

View 1 Replies View Related

C++ :: Vectors And Reading / Writing Files

May 19, 2014

How to write the code for this with the following requirements:

download the text file weblog.txt

This file is an Apache web log taken from the web server for St. Mary's University. When a visitor goes to their web site, the visitor's browser makes a request to the web server to view a web page, which is a file residing on the server. Each time a page is requested by a browser, the web server records information about that request. This weblog.txt holds the details of some of those requests.

Create a non-member function to read each line of the web log file. This function must do error checking to ensure that the file is opened successfully, otherwise it must provide a message like "file not available" to the user.

Each line should then be stored in a vector such that the first element of the vector is the first line of the web log file. Because each element will hold an entire line from the file, the vector should be declared as a vector of strings.

Note: You must declare the vector in a function.

Create another non-member function to sort the contents of the vector. Make sure to pass the vector by reference or your sort will disappear when the function ends! Use the sort function with #include <algorithm> to do the sort; you do not have to write your own sort algorithm.

Create one more non-member function to write the contents of the vector to a file. Each element should be on its own line in the new file. The contents of the new file should look like the original input file once your program completes, but in sorted order.

Create a main function that calls all of your non-member functions.

View 2 Replies View Related

C++ :: Storing File Data In Array With Structure Type?

Feb 20, 2015

I have a structure

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

View 1 Replies View Related

C++ :: Reading Data File?

Nov 22, 2014

If i have a data,how to write the code for read this data?

View 1 Replies View Related

C :: Reading Data Into 2D Array From A File

Apr 29, 2013

I'm having issues reading to a 2d array from a file. When I try to read the data from my file into my matrix variable it simply doesn't read anything and leaves the variable unmodified. I've tried just reading the first piece of data in the main function and it doesn't work there either. I'm really perplexed at this point since I've never had an issue reading from a file before. Here's my relevant code:

Code:
int main(int argc, char** argv) {
double matrix[MINSIZE][MINSIZE]={0}, vectors[MAXSIZE][MINSIZE], ans[MAXSIZE][MINSIZE];
FILE * inFile;
inFile = fopen(FILENAME,"r");
if(inFile==NULL){
printf("File does not exist.

[Code] .....

View 4 Replies View Related

C++ :: Reading And Storing CSV File Data

Feb 21, 2013

I am working on a small c++ project where i read from a csv file with information in this format:

string,string,int
string,string,int
string,string,int

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?

View 4 Replies View Related

C++ :: Reading In And Initializing Data From File

Oct 30, 2014

Im familiar with fstream and know how to read in data, given that there is one type per line.

But I have a file that has multiple lines each containing a string (an address) and two double values (latitude and longitude).

Looking for support with the logic part of reading in data and initializing them to member variable.

View 1 Replies View Related

C++ :: Reading Variables From Data File

Feb 18, 2014

I can't get my program to read the rest of my variables from my data file it will only read the first two and my end of file won't work it keeps continuing on.

879.46
C 400.00
D 100.0
F 525.00
C 450.00
D 500.00
D 1000.00
C 2000.00
D 3000.00
D 3500.00
C 5500.00
C 500.00
B 200.00
C -235.00
D 250.00
H -500.00
D 500.00
E

That's my data it will only read the inital number and C and D but nothing else.

// develop algorithm to balance checking account make transactions

#include<iostream> // required for keyboard and screen I/O
#include<fstream> // required for external file stream
#include<iomanip>
#include<conio.h>
#include<string>

[Code] ......

View 5 Replies View Related

C++ :: WAV File Reading Wrong Data

Jan 19, 2015

I have been experimenting with a program that loads WAV file and tries to read 1s and 0s from audio file (binary coded information). So far I got working code, but the problem is that I'm not getting correct data. I do get somewhat similar data. The problem is that I get data that amplifies low amplitudes, so instead some noise and binary data I get lots of noise and hard to recognize binary data. My code is this

#include <stdio.h>
#include <iostream>
#include <math.h>
using namespace std;
// An unsigned char can store 1 Bytes (8bits) of data (0-255)

[Code] .....

This is wav file in binary viewer (after header)

0030 0032
00300035003200320035003A0048004A
004C0049004A00510049004300360038

and translated to decimal

48 50
4853505053587274
7673748173675456

and this is output from "wavosaur" program (and this one is correct)

0.001465
0.001526
0.001465
0.001617
0.001526
0.001526
0.001617
0.001770
0.002197
0.002258
0.002319
0.002228
0.002258
0.002472
0.002228
0.002045
0.001648
0.001709

You can see it's not the same. I do get the same data like I do from binary viewer, but I don't understand how they are translated to amplitude value. ? Where is the catch?

So this is not really question about c++, but about wav file structure and reading data.

View 2 Replies View Related

C++ :: Reading Data From Text File

Feb 25, 2013

I wanna read data from txt file with space divided each value like

1.00518 2.01903 3.01139 4.01343 5.02751 5.99913 7.00011 7.99851 8.99506 9.98015 10.9901 11.992 12.9923 13.9932 14.996 16.0034 17.012 18.0255 19.0366 20.0485 21.0505 22.0664 23.0455 24.0383 25.0374 26.0439 27.0378 28.0376 29.0576 30.066

I know the size of the data is 2*500.

In matlab I can use like

fid = fopen('example.txt');
data = fscanf(fid,'%f,',1499500);

how should I write in C++?

View 3 Replies View Related

C++ :: Multimaps - Reading File Data

Jan 16, 2013

I've got a problem with reading my file data but before I explain it I'll give some background. I'm programming a 2D Platformer using the SDL library for rendering.

My problem is that when reading in the data from the file it ignores all the data and just skips to the end of the function, I've attempted to debug it and the load function is getting called, the file is in the right directory and is being opened.

Here is my code:

Level.h
#include <vector>
#include <map>
#include <string>
#include <iostream>
#include <fstream>
#include "gameobject.h"
#include "miscobject.h"
struct LevelData {
// Multimap Prototype

[Code] ....

I'm not sure if it's the way I'm using multimaps. I should have mentioned that I put a break point in the multimap loops where it writes and inserts the objects and it doesn't seem to be hitting the functions, this is why I think there's something wrong with the multimaps.

View 3 Replies View Related

C++ :: Reading Data From Text File?

May 5, 2014

read some information from a text file. The program I'm working on is like a simple betting program.

What I need to read are:

match_code - team1 - team2 - odd1 - odd0 - odd2
139 Atletico Madrid - Real Madrid 2.853.40 2.35

But the spaces between datas are not known. We only know that both team names may contain more than one word and there is one space, exactly one dash and one more space (" – ") between team names.

Also match_code is an int and odds are double values.

while(getline(input, line)) {
istringstream ss(line);
ss >> match_code >> team1;
string temp;
while(ss >> temp) {

[Code] .....

In that missing part, I need to get the second word of team name if there is one; and the three odds that are odd1 odd0 and odd2.

View 2 Replies View Related

C++ :: Reading Data From A Text File?

Feb 10, 2015

Each line of the text file has first name, last name, and a salary. Something along the lines of this:

john doe 4000
bob miller 9000

I want my program to take the first name, last name, and salary of each line and assign them to strings. I have tried this so far:

while (inFile){
inFile >> firstName;
inFile >> lastName;
inFile >> grossPay;
cout << firstName << " " << lastName << " " << grossPay << endl;
}

When it outputs the names and the salary, the last line of the text file gets output twice by the program.

View 1 Replies View Related

C/C++ :: Program Is Not Reading Data From DAT File

Feb 15, 2014

I'm not sure why my program isn't reading data from the dat file. I'm not sure if it's because I messed up my pointers, or I'm missing something. I know we usually use Infile >> blah >> blah >> blah; to get the data from the file, but my instructor showed an example that had the struct read it for you in this format and I could just call it with pointers.

#include <iostream>
#include <iomanip>
#include <fstream>
#include <assert.h>
using namespace std;
using namespace System;
typedef int Integer;

[Code] ....

View 12 Replies View Related

C/C++ :: Getting Junk Value After Reading A Data From File

May 28, 2013

I am getting junk value in file,if i write a integers to file.can body tell me what's the prob.

int main () {
    FILE*          fp = NULL; 
    UINT32         data[4];  
    UINT32         i = 0;
    UINT32         res[MAX_SIZE];
    UZN_STATUS       status = UZN_SUCCESS;
    UINT32         count = 0;
    /*Creating file called x*/  

[Code] .....

View 2 Replies View Related

C++ :: Reading In Data From File In Certain Format

Nov 22, 2012

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).

View 2 Replies View Related

C++ :: Reading Data From File And Manipulating It?

Jul 7, 2012

File Data format

A,A
A,B
C,E
C,F

And so on ... it could be up to any alphabet. The number of As and Bs and Cs and Ds in first column depends on the number of unique alphabets used in the first column. For example the unique alphabets used in this case are 2 (A,C) hence each alphabet appears in the first column of consecutive 2 rows.

Which means

Code:
A:A,B,C,D
B:B,C,D,E
C:C,D,E,F
D:D, ,F,G (E is missing)

Actual Data
A,1
A,2
A,3
A,4
C,18
C,33

Final Solution: Add each integer value to its previous value and store the resulting value.

View 8 Replies View Related

C++ :: Reading File Then Printing Data Onto Other File

Nov 7, 2014

I am reading a file then printing the data onto the other file. It is working, however when I check to see if each variable is being properly set after reading the file a issue arises.

Example of the file being read

Code:
Vehicle PV50CAN passed camera 1 at 05:33:26.
Vehicle W867BRO passed camera 1 at 05:33:29.
Vehicle KQ63ARU passed camera 1 at 05:33:38.
Vehicle K954ITQ passed camera 1 at 05:33:40.
Vehicle V220MXB passed camera 1 at 05:33:42.

[Code] .....

View 14 Replies View Related

C++ :: Reading Data (Constant Numbers) From A File

Feb 24, 2015

How do I get c++ to read a file containing six numbers - a1, b1, a2, b2, a3, and b3 - that are constants for the following equations:

clubangle(degrees) = a1 + b1*0.85*clubnumber

clublength(inches) = a2 + b2*1.05*clubnumber

clubspeed(yards/s) = 1.1 * (a3 + b3 * swingnumber) * (clublength(inches)/40)^2;

View 5 Replies View Related

C :: Reading Data From CSV File Or Memory Onto Screen?

Jul 26, 2014

I have a csv file (comma delimited text file really) and I have data ,about 6400 lines, and I need to read and display data from 1 line. At the bottom is sample data from my csv file.

I want to read onto the screen the 3rd item .. ie Test User 1 and the date and time at the end (the last 2 items).

I will enter in a number .. from which I will want to retrieve the appropriate record .. in this case I would enter in 514, 563 or 874 and get back the info for that record.

This is a DOS 16 bit application .. and I know that some of the data is in memory already but I am not sure how to tell .. or how to retrieve it.

I do have the ability to save the data to the file at any time .. so I can use that to ensure that the data is current in the text file before I retrieve the data from this 1 row.

I think that it may just be easier to get from the text file ? but I am not sure.

0000,7,0,"Test User 1",53c145cb,db,5,514,514,2014/07/12,10:27:23
0001,7,0,"Test User 2",53d7f,1903,10,563,563,2014/07/24,11:04:31
0002,7,0,"Test User 3",529c,5ffb03,0,874,874,2013/12/02,09:07:58

I am a database guy .. and I am just a bit lost when it comes to C programming as such.

View 9 Replies View Related

C :: Reading Data File Into Array Of Structures?

Nov 2, 2014

I'm reading the following file:

Osgood,Marcus 298542123 CHM FR mosgood@whatever.edu
Cronk,Melissa 873489021 BIO SR mcronk@whatever.edu
Pry,Seth 349908431 MTH SO spry@whatever.edu
Langlais,Susan 783323545 ME SR slanglais@whatever.edu
Davis,Nicole 987543345 PHY FR ndavis@whatever.edu

It's supposed to split it up into name, ID number, major, year, and email. The file reads it without any errors, and assigns name to the first part of the structure. However, ID gets assigned the ID, major, year, and email. Then Major gets assigned major, year, and email. Year gets assigned year and email, while email just gets assigned email. I don't know if it has something to do with the loop. For example, this is what I get what I print just the name and the ID.

Cronk,Melissa 873489021BIOSRmcronk@whatever.edu

Pry,Seth 349908431MTHSOspry@whatever.edu

Langlais,Susan 783323545ME

Davis,Nicole 987543345 PHYFRndavis@whatever.edu

Anyway. This is my function code for reading the array. I have it printing the ID number just to see if I can catch the errors earlier:

Code:
#include <stdio.h>
#include <string.h>
#include "functions.h"
void read_data(char filename[], studentinfo_t s[], int *size) {
FILE *infilep;
int countstudents = 0;
infilep = fopen("student_data", "r");

[Code].....

the name is reading correctly, but not anything else!

View 1 Replies View Related

C :: Reading Data From A File And Adding Them To A List

Jun 1, 2014

I've been trying to write my homework assignment (a list of countries, their codes and their capitals) and I've done most of it but I'm stuck at this: I have to open a file, read it and if there are data, add them to the list. So far I've created an element of the structure, queue list, printed the list on the screen and freed the memory. I thought that for reading the file and adding the data I could first open the file (of course) with fopen and after that use a for loop (i=0;i=!EOF;i++) to scan the whole file and fscanf(fp,"%s",result->country),etc in the loop to add the data to the structure of the element and finally insert that element to the queue list. However, when I try to do these operations, I only get to writing the name of the file and the program crashes.

Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct List {
char country[20];
char code[5];
char capital[20];
struct List*next;

[Code] .....

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved