C++ :: Reading Records From Files

Jan 28, 2014

Is there a way to indicate how many records exist in a given file? For example, vectors have the vector.size() command to show the number of given elements. Is there a such command for files and records?

View 6 Replies


ADVERTISEMENT

C++ :: Update Records Using Sequential Files?

Nov 3, 2013

How do i go about updating a specific record in sequential File using a primary key in c++. I used Inventory number as my primary key..

Code: int locate[2];
string fname, lname, add, name, address;
int num, foundit;
Customer customer;

[Code].....

View 6 Replies View Related

C/C++ :: How To Use Text Files As SQL Fields To Edit / Delete And Modify Records

Aug 19, 2013

I want to search and display the field stored in text file and also i want to delete the field that is entered. Case 3 and 4 is incomplete.

#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main() {
    int a;
    int st_id;

[Code] ....

View 6 Replies View Related

Visual C++ :: Reading Records From Input File And Do Some Statistics

Oct 1, 2014

The program will prompt the user to enter a every student's first and last name, major ( of 4 choices CMPS MATH PHYSICS or EECE ), and grade. it's agreed that the professor will enter the name NoMore to stop the entry.

the program willl then store the info in a txt file. after closing the input file, the program will open it again read the records one at a time until end of file, and do some statistics including: highest grade, average grade, and highest average by major.

Finally the program will print the results....

View 6 Replies View Related

C++ :: Files Reading From PDF?

Feb 26, 2013

How do I read a .pdf file using C++? When I try to open it using myfile.open ("example.pdf"); but all I see is some Crazy Symbols. Is there any way to open ?

View 3 Replies View Related

C++ :: Reading In Values From Txt Files

Dec 22, 2014

I cant seem to read stuff in from my students.txt file which contains this

19992195 John Smith 20 05 1995 09 09 2011 15 05 2014 55 65 72 58 80 45 40 45 66 78 88 81
20051195 Mark Dobson 20 05 1995 09 09 2011 15 05 2014 55 65 72 58 80 45 40 45 66 78 88 81
20063196 Paula O'Reilly 20 05 1995 09 09 2011 15 05 2014 55 65 72 58 80 45 40 45 66 78 88 81
20053344 Aoife Cleary 20 05 1995 09 09 2011 15 05 2014 55 65 72 58 80 45 40 45 66 78 88 81

It has something to do with the lines at the bottom of the code. It doesnt cout anything. The program just crashes upon execution. First, it asks me the amount of students i want to handle. I enter '1'. Then it asks me if i want to read in from external file and i enter 'Y'. then the exe just crashes

#include <iostream>
#include <cstddef>
#include <cstdlib>

[Code]......

View 3 Replies View Related

C++ :: Reading And Writing Files?

Feb 20, 2015

I have to write a program that sorts names and grades from a file and output them to another.

For example:

Name: Peter Parker
Exam 1: 95
Exam 2: 90.625
Exam 3: 91.20

Name: Mary Smith
Exam 1: 65
Exam 2: 79.1234
Exam 3: 70.24

Becomes something like this in the output file:

Name: Parker, Peter
Average Score: 92.28
Grade: A

Name: Smith, Mary
Average Score: 71.45
Grade: C

I know I'm supposed to read the whole file, but I'm getting really confused on how to take the name of each student separately without recording Exam 1, 2, and 3. I'll be able to do the average score and grade on my own.

View 2 Replies View Related

C++ :: Reading From 2 Files And Merging

Oct 3, 2014

The directions are to write a program that reads sorted integers from two separate files and merge the contents of the file to an output file (third file). The only standard output will be any errors to be reported and a “FINISHED” statement after all items have been processed.

file1.txt
2
4
6
8
10

file2.txt
1
5
11
12
15

Output.txt
1
2
4
5
6
8
10
11
12
15

This is the code I have so far, but it is not working, and I have put the two txt files in the same directory as my .cpp file. It is not working though still. What have I done wrong and how can I fix it to read these integers from the two numbers and merge the contents into a third file?

#include <iostream>
#include <fstream>
using namespace std;
int main() {
int num1;
int num2;
ifstream inputFile;

[Code] ....

View 5 Replies View Related

C/C++ :: Reading From Files And Using Functions?

Mar 24, 2014

My question portion is attached. The code I have written is below.

#define _USE_MATH_DEFINES // for C++
#include <cmath>
#include <iostream>
#include <iomanip>

[Code].....

View 3 Replies View Related

C/C++ :: Reading And Writing Files

Jan 16, 2015

I'm messing around with reading and writing files. The first file creates a small txt file. Simple enough

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main(){
string name;
string desc;

[Code] ....

It does what it should. It creates a text file "items.txt" .... It reads as such:

dagger,a dagger,15,10,0,1,3,1,0,0,0,1,0,0,0,0,0,1

The second file is meant to read the file and place the data back into the variables. This happens, but the data crams itself into the first variable, and the rest of them collect the trash that's in memory.

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
string name,desc;

[Code ....

I need to get "dagger" into name, "a dagger" into description, and each value with their perspective variable. I'm sure I need some type of "separator". Hopefully I can use the comma. Before it's over, I will have about a hundred items that will need to be read into a class of items.

View 4 Replies View Related

C/C++ :: Reading Numbers From Two Files

Jun 11, 2014

My assignment was to take numbers from two different files, and merge them into a third file in numerical order. I have everything working well, but the output shows the lowest number everytime and i'm not sure why. logical error ....

Sample:
File1 File2 File3
10 12 10
20 25 12
30 37 10
40 49 25
10
37
10
49

Here is my code as well

#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
int main() {
ifstream File1, File2;
ofstream Output;

[Code] ....

View 14 Replies View Related

C++ :: Reading BMP Files Headers

Apr 19, 2013

Code:

struct magic {
char windowsheader[2];
} magicnumbers;
struct bmp {
unsigned int sizeofthefile;
short int applicationspecific1;

[Code] .....

When I run this program, seems like it is working,at least I am sure that it gives the right file size. But if I don't use struct magic and instead use:

Code:
struct bmp {
char windowsheader[2];
unsigned int sizeofthefile;
short int applicationspecific1;
short int applicationspecific2;
//same lines with above
} bitmap_header;

And if I don't use first fread:

Code:

fread(&magicnumbers,sizeof(magicnumbers),1,fp);

Then the values which structure "bmp"'s variables get become wrong. Of course I change the related printf to:

Code:
printf("
windowsheader:%d %d
",bitmap_header.windowsheader[0],bitmap_header.windowsheader[1]);

Why does the problem happen,what is the difference between them?Why do I have to use separate structs?

View 2 Replies View Related

C++ :: Reading FASTA Formatted Files?

Nov 27, 2013

reading fasta formatted files. Usually ppl from computation biology know what that is but for those that are not here is a quick guide :

Fasta formatted file:

Code: >header
seqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseq
seqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseq
seqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseq
seqseqseqseqseqseqseqseqseq
>header1
seqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseqseq
seqseqseqseqseqseqseqseqseqseq

... so a very simple file format. and what i need to do is to read that into memory (vector of strings) so that header info and seq info is in two different vectors. for that i am using the following function :

Code:

sequence and headers vectors are class variables:

template <typename TStr>
template <typename FS>
void FastaSeq<TStr>::ReadFasta(FS& fs){
string line;
string seq;
while (fs >> line){
if(line.c_str()[0] == '>'){

[code].....

this code does what is suppose to do but it is EXTREMELY slow. it takes me exponentially more time to read the seq in memory then to process it. when compared to c style alternative that reads character by character it takes 13 sec with this function to do the same job that my c function does in 0.03 sec. How to improve upon this function to make it comparably fast (also i am using optimization) ?

View 10 Replies View Related

C :: Reading Files Of Unknown Size

Jan 23, 2013

I want my program to be able to read text files in the format:

number number
number number
number number...

and so on, so there are two columns of values. The problem I'm having is, there are a lot of numbers in the file, and it can vary. The program needs to read the numbers, put one column into one array, and the other in another, perform some operations on it all, and eventually pop out two different arrays. In other words, after I've got these arrays, I don't need them for much longer. I was hoping I could dynamically allocated some arrays to store the numbers and just free them as soon as I'm done with them.

If the file wasn't of such variable size or if it was guaranteed to be under a certain number of variables, I would have used:

Code:

while ( fscanf(input, "%lf %lf
", &col_1[], &col_2[]) == 2 )
{
no_rows++;
}

The problem is I want to allocate "no_rows" as the array size, which I don't have until after I have read the file.

View 9 Replies View Related

C :: Error While Reading Files In Directory

Sep 7, 2014

I use this header dirent.h to get list of files in directory

[URL] .....

I am using code::blocks on windows XP.

Directory "kernels_source" is placed in project's directory where I am running the code.

Code:

#include "include/types.h"
#include "include/gaussian.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

[Code]....

View 10 Replies View Related

C :: Program Reading / Writing Files

Dec 10, 2013

program that I am working on. I want to use fgets() in my program so I could handle multiple words from a text(to be able to handle spaces). I get a weird result when running the program.

Code: #include <stdio.h>
#include <stdlib.h>
//#include "kim.h"
#include <string.h>
[code]....

View 4 Replies View Related

C++ ::  Reading Files Saved On Computer

Jul 20, 2014

I can't seem to get my program to read a file that's saved on my computer. Here's my code:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
ifstream inputfile;
string name;

[Code] ....

View 6 Replies View Related

C++ :: Reading TXT Files - 0 Unsatisfactory Score

Dec 10, 2013

int main() {
double x, avg, max=0.0, min=100.0,totalsat=0.0, totalunsat=0.0, totalout=0.0;
int invalid=0, outstanding=0, satisfactory=0, unsatisfactory=0, kount=0;

ifstream inFile;
inFile.open("grades.txt");

[Code] ....

When the program tries to open the text file it just scrolls "0 unsatisfactory score" forever. The text file has grades in it I'm trying to sort

63
75
121
72
72
78
67
-9
80 .....

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/C++ :: Reading And Writing In Binary Files?

Jun 5, 2014

why I'm giving "Access violation reading location 0x336827B8" and also I was able to read my data but it's giving me weird stuff. I want to write the sorted grades and the average in a new disk file. so here's my code so far here's my code

#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
int avg(int sum, int size);
void swap(int *, int *);

[code]....

View 5 Replies View Related

C++ :: Reading Large Number Of Binary Files

Apr 14, 2014

Windows 7, 64 bits, Visual Studio 10.

I have a problem to read a large number of binary files, process them and store them under a new name. The program and routines go very well for 505 files. After reading 506 files, the program now refuses to read the next file. I have 16 Gb of memory and tried to close all other programs and restart the PC. it always stops after 506 files (512 files would be more understanding in a way...).

Here is my code. I have tried many things without success. This is only part of the loop that stops. The if test if (myfile.is_open() returns false by some reason. I can start the process again starting with the file that does not open and then it stops again after 506 files.

char * tfiBlock;
ifstream myfile (OrigFilename, ios::in|ios::binary|ios::ate);
if (myfile.is_open()) {
int lengde = myfile.tellg();
tfiBlock = new char [lengde];
//static char memblock [size];

[Code] .....

Clean up procedure:
delete[] tfiBlock;

Are there any limits to how many files that can be opened, or is it maybe someting to be set in the compiler?

View 5 Replies View Related

C++ :: Reading Multiple Text Files In Program

May 31, 2013

I want to know how to read multiple text files in this program... I have 5 text files(order1,order2,...order5).

#include<iostream.h>
#include<fstream.h>
#include<conio.h>
#include<windows.h>
using namespace std;
class{

[Code] ....

View 3 Replies View Related

C++ :: Reading Source Code From Uncompleted Files?

Jun 9, 2013

I know it sounds strange but I've seen things that have files which contain source code (usually in something in Python or such) and how this is read on run-time?

View 1 Replies View Related

C++ :: Writing / Reading String Objects To / From Files

Jul 7, 2013

I am using the code below to write a single instance of object "Employee" to a file in Binary mode. The write part seems to work fine, however when I try to read the single employee object from the file into memory I get a double free or corruption error.

I think this has to do with the fact that I am using a string data member in the Employee class but I don't understand what is going wrong. I have read that strings can vary in length and use dynamic memory allocation but if I write a single employee object to a file with data member 'name' equal to "John", it should be the exact same size when I read it back in right?

The code below works with no issues when I omit the string data member. Why is that? Where is the memory for the string object being "double released" when I read the employee object back into memory from the file?

I am using Linux Mint 15, Eclipse June and GCC 4.7.3 with the -std=c++11 option.

#include <iostream>
#include <fstream>
#include <string>

[Code].....

View 3 Replies View Related

C++ :: Opening And Reading Files With Input / Output?

Oct 15, 2014

I'm in a CIS 143 class which is Introduction to Programming using C++. We've been assigned a lab with little to no detail on how to do the things listed.

The purpose of this lab is to practice the file input and output concepts. For this lab you may assume that the input files exist and contain appropriate data inside of them.

Four separate text files* which contain the following lines, different for each file.

(*: This isn't on the lab, but don't worry about what the name, age, id, and major are. those can be random and I can just change them what they need to be)

Name
Age
Student ID Number
Major

Your program should ask the user which of the four input files they would like to open, and then read the contents from the file. Once the contents have been read in, it should output to both the screen and a file named "output.txt" the four values were read in, arranged as follows:

"Hello <name>! You are a <age> years old <major> student, and your ID number is <ID number>"

Now I am by no means saying "Do it for me". I just need to know how to have a user type file1, file2, file3, or file4, and then have the program open that file, then have the output.txt file arrange the wording into the sentence above.

This is what I have so far and I don't think it is anywhere near correct:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
ifstream inFile;
string file1;
string file2;

[code]....

View 1 Replies View Related

C++ :: Reading Stream Data From PDF Files Compressed In LZW?

Nov 28, 2013

I'm trying to read stream data from a stream in a pdf file compressed in LZW. My first step is to read this compressed data into a buffer. The second step is to decompress it. I know how to decompress it, it is the first step I am having trouble with.

How should I read this data? If I read each character into a char the numerical output will not exceed 256. LZW compressed output should exceed 256.

I read the pdf in binary mode and have tried the read function like below.

From what I understand (don't quote me), I should be reading in 12 bits at a time. Is that correct and if so should I be using a bitfield. If I do need a bitfield then how to I read the data from the stream into a bitfield of 12 bits without restricting the binary value of the characters being read from the compressed stream.

Code:
ifstream inputfilestream;
inputfilestream.open("myfile.pdf", ios::out | ios::binary);
char mychar; //unsigned char gives an error though it can be //converted to unsigned char later.
while (inputfilestream.read(mychar, 1)) {
// do something with the char.. I have stored it in an int vector
}

View 14 Replies View Related







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