I'm using maps and writing files for the first time and I get a crazy compiler error when I try to compile the following code.
//map is named schedules
// saveSchedule() is a member of the Schedule class that writes a vector of objects to disk, or is supposed to
ofstream newFile("sched.txt");
map<string,Schedule>::iterator in;
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.
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.
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.
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.
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 *);
I am trying to use myfile to create and write user data to a file [URL].
At the moment I only want to save as .txt so that I can open it to see that it wrote to file properly.
The main issue I get is that it says the file is not open when my program gets to the error checking at the very end, a few guides mentioned that if the file was not yet created a file with the specified name would be generated in the same folder as main on the hard drive. I did try creating the file as a notepad .txt file but it still read the error. Here is the snippet concerning the writing of the file:
it compiles fine with the rest of the program and everything runs smoothly, it just isn't writing to a file.I have included <string>, <iostream> and <fstream>.
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.
So lately I've been writing multiple header and cpp files and I would always the same error when I finally #include headers in my main.cpp. This error
Code: undefined reference to `...`
On Youtube videos I see people doing this and their work magically compiles correctly. I found out that when I #include the headers' cpp files instead, my programs would compile. I use Code::Blocks with GNU GCC compiler.
#include <stdio.h> #include <tchar.h> #include <iostream> #include <string> #include <fstream>// enable writing to and reading from files #include <cstdlib> #include <time.h> using namespace std; class Person {
[Code] .....
Error list:
Code:
Error 1 error LNK2019: unresolved external symbol "void __cdecl saveperson(void)" (?saveperson@@YAXXZ) referenced in function _main H:Cry_DevProgrammingC++Using_class_ in_ c++Using_class_ in_ c++Using_class_ in_ c++.obj Error 2 error LNK2019: unresolved external symbol "void __cdecl displayperson(void)" (?displayperson@@YAXXZ) referenced in function _main H:Cry_DevProgrammingC++Using_class_ in_ c++Using_class_ in_ c++Using_class_ in_ c++.obj Error 3 error LNK2019: unresolved external symbol "void __cdecl editperson(void)" (?editperson@@YAXXZ) referenced in function _main H:Cry_DevProgrammingC++Using_class_ in_ c++Using_class_ in_ c++Using_class_ in_ c++.obj Error 4 error LNK1120: 3 unresolved externals H:Cry_DevProgrammingC++Using_class_ in_ c++DebugUsing_class_ in_ c++.exe 1
I am writing a program to hide files behind other files using Alternate Data Streams in Windows NTFS file systems.
The program is as follows:
Code:
#include <stdio.h> #include <stdlib.h> int main(void){ char hostfile[75], hiddenfile[75], hiddenFileName[15] ; printf("Enter the name(with extension) and path of the file whose behind you want to hide another file: "); scanf("%75s", hostfile);
[Code]...
The complier is showing error as "Extra Perimeter in call to system" but I am not getting where?
I am writing a piece of code that requires me to display the last 1000 lines from a multiple text files (log files). FYI, I am running on Linux and using g++.
I have a log file from which - if it contains more than 1000 lines, I need to display the last 1000 lines. However, the log file could get rotated. So, in case where the current log file contains less than 1000 lines, I have to go to older log file and display the remaining. For e.g., if log got rotated and new log file contains 20 lines, I have to display the 980 lines from old log file + 20 from current log files.
What is the best way to do this? Even an outline algorithm will work.
This project is a Atmega 2560 connected to a serial GLCD screen.I've got serial communication working perfectly.Now as you can see I wrote a function that sends 1 single character to the UDR1.I wrote a function that uses this first function for sending entire words (strings).All of this works great.
Next challenge is writing a "int byte" to the GLCD screen.In this case the variable "voltage" has a value of 100.I'd like to write that 100 to the serial display via the uart.But whenever I do this the screen reads this 100 as a ascii decimal number... (= d)
I've tried things like
LCD_PrintStr("voltage"); (Result: The word voltage shows up on the screen) LCD_Write(voltage); (Result: write ascii letter for dec 100 (= d ))
I'm writing a program using Huffman algorithm to compress text file. I have tested my program by just printing the printing ASCII character to file and it worked fine. However, now I have to implement using bits and my program doesn't work. It seems like I'm not reading or writing the right bits. Here is the result of my testing:In the input file I put abc the input file to compress it. Then I uncompress it the out out is aaa. Below is a snippet of how I read and write bits
Code: class BitInput { istream& in; // the istream to delegate to char buf; // the buffer of bits int nbits; public:
I have a question about an issue I am having on my final project. Within my ItemEntry.cs form, I am trying to get the application to append the already existing .txt file, rather than prompt the user to replace it. I can't seem to get the StreamWriter and FileStream to allow the user to write to the file.
Code: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq;
I am trying to write a structure to a file. Example say the structure has two variables x and y . I want to write a function which modifies these variables and stores the modified version on a file. Such that next time I call the function . it has the values from the previous write. Here's an example of my code .
// do some calculations. fwrite(mystruct, sizeof(MYSTRUCT), 1, fp); fclose(fp)
//return some value }
The problem is that each time I run the program it shows the initialized value of the variables and not the value from last write. I guess the write isn't successful because when I open in w+ mode. i get the error file could not be opened and then i have to delete the file and re create it....
Code: #include<stdio.h> #include<string.h> #define a 9 #define b 9 #define c 3 int main() {
[Code] .....
In practice section there was a challenge to print up numbers in letters up to billion including negatives I didn't look at the solution and came up with this but it is getting difficult after this point....
I have a text file containing 500 signed decimal numbers. My task is to read each entry and convert into a 16-bit 2's complement representation (binary number) and write into the another text file.