When i execute the program it gets the right data for the first array but the scound either doesn't work at all or just gets to much data. i've tryed using getline and the "cin" for what the file would be in this case "myfile" there is also one more array that must be retrieved from the file.
#include <iostream> #include <fstream> #include <string> using namespace std;
And here is the contents of the file: jack 01014 jgd
Moh 02925 Tyeu
When I run it on dev c++, a message appear saying that the prog has stopped working and no output appears. I want to put the name in user[n].name, the phone number in user[n].phoneNumber and the address in user[n].address
Suppose your program has many concrete subtypes of Person, and each person will have their own file saved, with their type stored in that file. When reading the files to create the people again (of their proper types), what is the best method to maximize performance (and elegance by shortening the code)? Here is what I have so far.
First I used if statements, which is terrible, and now I've improved the performance logarithmically using std::map. I still suspect there is a better way, especially if there are going to be hundreds of different classes. If you want to test it, you can change the PATH constant to whatever path you want, or just leave it as an empty string, and the files will be created in the same directory as your cpp file. The part I'm trying to improve is pointed out in the comments.
struct Person { std::string name; Person (const std::string& newName) : name (newName) {} virtual ~Person() = default; }; struct Guy : Person {using Person::Person;}; struct Girl : Person {using Person::Person;};
I know how to save/open files but im just confused on where to write the code for it in this block of code :
#include <iostream> #include <fstream> #include <string> #include <iomanip> using namespace std; const int NUM_MONTHS = 12;// Number of months const int NUM_CATEGORIES = 6;// Number of categories
Right now I'm working on an assignment where I need to take the data from on file encrypt it by adding 5 to each byte and then save it to a user specified location. I think I'm close to having it done but I've run into a hick up. After I get the user input for where the encrypted data should be saved the program seems to never end. This is the code I have so far
#include <iostream> #include <fstream> #include <string> using namespace std; int main() { ifstream input; ofstream output;
I want to take the informaition from this file and save it into a struct the file conteins name age year (in char) and a grade it is somthing like this
file Nikos Tolis 19 A 8 Iwanna Nikolaou 20 B 9 Kwstas Doukas 20 Β 6 Georgios Pappas 19 A 7 Iwannis Lekatis 20 Β 7 Nikos Ntoumas 19 A 5 Maria Oikonomou 20 B 6 Kwstas Argyrou 19 A 10 Irw Ntouma 20 B 8 Leuteris Doukas 19 A 6
I want to read till i found the '32' the space in ascii here is my code so far
Code: #include<stdio.h> #include<string.h> #include<stdlib.h> struct students { char *name; int age;
My project involves writing a c program to generate a set of 70 decimal numbers. I want to save the output (these 70 numbers) as a txt file. I tried the following:
1. prt scr of output screen and pasting it in notepad. NOT WORKING 2. going to DOS SHELL and doing the following: c:TCBIN>output.exe>>output.txt NOT WORKING. Text file is generated, but it does not contain output. It just says: illegal command: output.exe
Interface class Person{ private: char name[80]; short age; public: void get_data();
[Code] .....
This is a simple example from and old Lafore C++ book, with a few tweaks by me. The point is simple. Save object person to a *.dat file, exit the program, then start up program again, open up *.dat file, and load contents.
The first problem is the compiler is printing a bunch of Asian characters to the file (is this normal?)
The second problem is, it's not loading the object as it should, giving me a bunch of gibberish.
I have been working a while with saving and retrieve structs, and I still have not got it to work. I get Segmentation fault sh "${SHFILE} . I have search this error, and it has something to do with memory, but what, since I am a beginner with saving and retrieving files. The project runs fine, and the error stated above outputs into my console window as text.
I started with C# 2 days ago, but i have made 3 "games". Its something like Cookie Clicker, very simple and very easy.
But I have problem with saving the game. I want to save values of variables to text file when i click on button, and when i click on another button i want to values of variables load. Just simple save system. How it works and so.
I'm very new to c and c++ and am currently working on a Caesar cipher that grabs encrypted text from a txt file and decrypts it onto a new txt file. My code builds fine in CodeBlocks and when I run it, there is a new txt file created but it stays blank.
#include <iostream> #include <fstream> #include <string> #include <stdlib.h> #include <cstdlib> using namespace std ; int main(int argc, char *argv[]){
I'm intrested in creating programs of games and such which learns while playing and saving the information for further use. For example a tic tac toe game where the program saves evry game it won or lost and creates a tree of some kind that store the information of the game and save it in a file when the program is being quit. The problem i'm having is how to save a tree in a file efficently.
I have written code that saves a matrix to a utf-8 file. This code works just fine when invoked from a win32 console app, but if I attempt to use the exact same code by invoking it within a SDI Doc/View Serialize(CArchive& ar), if(ar.IsStoring), it fails, but in a somewhat unusual manner. Namely, the file shows up in the designated directory, but it is an empty file (0 bytes), and the 'Unable to open file' message is seen in Debug config. Note that both the win32 console app and the SDI app are both using a Unicode character set, however, only the SDI app uses the method inside a Serialize(CArchive& ar) method, whereas the win32 console app evokes the save method directly from within _tmain. Why this seemingly illogical disparity occurs.
Here's the template code I have used in innumerable applications to save matrices to a disk file.
Code: namespace TNT { // saves a TNT double matrix, discriminating between real and complex matrices by virtue of the respective file markers, 'MATCALC94R' and 'MATCALC94C'. template <class T> void SaveRealBMatrix(const Matrix<T> &M, string sfilename) { _RPT0(0, "SaveRealBMatrix: "); _RPT1(0, "sfilename =: |%s|
[Code] ....
Here's the code from the SDI document Serialize(CArchive& ar) that fails as described above. Note that m_M is a class member TNT::Matrix<double> m_M that has been verified to exist in the Serialize method.
I have a program that saves all information temporarily into memory (into the array), however, I need a permanent save solution. I have the full program working correctly, formatted perfectly, but it's missing the file array to file output.
Essentially, whenever I'm presented with the menu I'll be able to add entries, search by last name, show the entire list, and exit and save. Whenever I select option 4 the program should save to a file "address_book.txt". Whenever I reload the program, it should load from "address_book.txt" and populate the array with the preexisting data.
My question is focused on how and where I should implement the file output. What I have thus far:
#include <iostream> #include <string.h> //Required to use string compare #include <fstream> //Eventually used to store array into file using namespace std; class AddBook{
I am using fin.peek() to read character from input file and saving each character into an array. Each line from the input has first name, last name, id number, and then 5-6 grades. Random spacing between each one.
input file example: Adam Zeller 45678 80 87 60 90 88 100 David Young 34521 34 56 76 76 76 76 Carl Wilson 909034 90 90 90 49 39
my code for reading in and storing each character is this:
while(fin.peek() == ' ') fin.get(); while(fin.peek() != ' ') ///// first name { c = fin.get(); first[i] = c;
[Code] ....
The problem I am having is what sort of loop would go around this to read till end of file. I have tried eof. I have tried while(!fin.peek == ') and I have tried a couple of other methods. these methods resulted in a never ending loop execution.
I am trying to save the excel file in D:/newfolder. but the file saving as newfolderFilename. The newfolder is already created in D drive. File save path i am getting from textbox ....
I would like to have 2 functions. (FYI, I haven't even tested these because I don't have a compiler on this PC, so don't know what they'll do. I'm also new to C++, self-teaching.)
My question is, I'm sure that oFile should be type object (of some sort), not int, but I'm not sure how to reference it correctly so that it passes from FileOpen to main to FileClose.
Code: #include <iostream> //I/O using namespace std; #include <fstream> //files using namespace ios; int FileOpen(string fileName) { ifstream oFile (fileName); //attempt to open file