C++ :: Multiple Data Streams In One Class - Handling All In One Member
Jan 24, 2014
I have to implemente the to_string method. Whats the fastest way? Stringstreams. But I have to use C++ without any headers, so I need to implement the stringstream class. How can an stringstream hold one float? An double? Hoq cqn I implement an strigstream myself?
The goal is to write a c++ program to read the employee.dat(which is this text file below) file created and produce a duplicate copy of the file named employee.bak.
Anthony A 10031 11.82 12182010 Burrows W 10067 12.14 692011 Fain B 10083 10.79 5182011 Janney P 10095 12.57 9282008 Smith G 10105 9.50 12202006
and then the second question is to modify this program to accept the names of the original and duplicate files as user input.
#include <iostream> #include <fstream> #include <cstdlib> // for exit #include <string> using namespace std; int main() { ifstream inFile; ofstream outFile;
I recently discovered the new - new to me anyway! - feature of modern C++ that allows you to set the initial value of a data member when you declare it:
class CINTWrapper{ private: int m_iData=0; };
This even extends to calling member functions that work with initialization I believe:
class CStringWrapper{ private: wchar_t* Allocate_Array(const int iBufferSize); wchar_t* m_pString=Allocate_Array(1); };
At first, this seemed an extremely useful piece of functionality that C++ had been lacking all along. However, the more I thought about it the more it struck me this feature actually undermines one of the principle design elements of the language - that being the Constructor.
As I understand it the primary purpose of the Constructor is specifically to give the programmer a place where it is guaranteed he can always initialize his data members before anything else is done with the class. However, given the new initialization rules this is no longer necessary. So it largely seems to me that Constructors as a whole are no longer necessary either! Copy-Constructors are a special and vital case. Admittedly when I was using them for their intended purpose I hated either the redundancy you had to introduce across multiple Constructors; those with and without arguments and so on, or alternately the fine tuning of helper-functions to do common initialization between these variants. Now however I sort of regret this cast-iron rule has been taken away.
As a last point, I am trying to change the way I think about programming. I am trying to employ more objects than pure C-style ('int' or 'double', etc) data types and especially to move into templates (although absolutely NOT the Hewlett Packard template library!). Given my current understanding of inheritance in particular it seems to me that using pre-initialized data members rather than Constructor-initialization makes object derivation even more complicated, not less so.
I need to make a program which reads multiple lines from a text file and stores that information in a vector of structs(the vector class template also needs to be custom made).
One of my requirements is to have a class dedicated for I/O for the text file. At the moment I can't seem to get a way to input the data from a file into a vector from an InputOutput class. This is my code:
This is the menu selection function in the menu.cpp where i figured i would call the Input file and store it from case 1. I think I'm doing it wrong though. Is there a better way of doing this because at the moment i am getting some errors such as error LNK2019.
I have a small class with a static int data member. I want to zero init it. I am thinking that making a .cpp file with only one line seems too much, isn't it?
So, can I do it inside the the header file? The variable is going to enumerate how objects were created (so any alternative will do).
"You cannot initialize the static data member in the class definition — that’s simply a blueprint for an object and initializing values for members are not allowed. You don’t want to initialize it in a constructor, because you want to increment it every time the constructor is called so the count of the number of objects created is accumulated."
Why don't you want to initialize it in a constructor?
Edit: Because every time it is called it will set it back to 0 or whatever the initializing value.
For example, in a header file A.h, I define an abstract class,
Code:
// A.h class A { public: virtual void foo() = 0; private: static int _x; };
How'd I initialize static member data _x?Normally, we initialize a static member data in a cpp file. However, there is not cpp file for A.h. If I intialize _x in header file, there will be linker errors like mulitple defined symbols. What is appropriate way to do that?
Basically I want to create a base class which defines a static data member so that its automatically redeclared as the same static data member in the derived class.
class A{ protected: static derivable int val; // A::val }
class B : public A{ // static derivable int val is already here // A::val AND B::val }
This seems impossible to me but I'm wondering if perhaps there's a way to add modifiers to the compiler to do this (or preferably something MUCH simpler)...
I am trying to make a table class that will be able to have multiple columns of data. I want it to have something to hold data (I was using a 2D vector for only one data type) in it, somewhat like a pair, but for any number of data types. The class is a template to make it generalized.
I have looked a little at variadic templates, but I don't know how to declare the vectors for each data types then.
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 having a 1file (given file) and in that i have some binary information and i niw i want to convert those binary information into decimal form and save it into new file (output fle). I was written a code but that was not working properly.
Code : main() { int i,j,n,ch; int a[100][100]; FILE *p,*q; char file1[20],file2[20]; printf("enter the given file name");
Every time I write in file using ofstream it works fine except for one thing that when the file is re-opened after writing something and we try to add more data then previously added data is removed how to get rid of this.
<code>
struct abc { char name[100]; int a; }; int main() { ofstream file; file.open("text.dat", ios:ut | ios::binary);
Data handling for a UAV project I am trying. My background is in Microcontrollers but I have never had exposure to "sound" programming practice...
I have got 2 microcontrollers to drive a UAV craft I've made. One "firmware" micro collects all the sensor data and then passes it to the other "application" micro for control processing. Once decisions have been made this is sent back to the "firmware" micro so that actions are taken.
So in essence I am sharing a raw data chunk periodically between the 2 processors that has outputs and feedback data. For the moment this is captured as one big buffer array on either micro after receiving. For easier structure I thought of bouncing this buffer that contains all sensor information and control variables between the 2 processors (visualize a ping pong game with all the possible variables from both micros - bandwidth between the micros is not a limitation) There are quite a few modules that want to access information from this buffer and write control actions back to it.
I was thinking of constructing a struct on both micros to access this "raw data" from the buffer and set it up with variable names so that it is easier for functions to read info and write controls back.
But this would mean that the data is accessible to every function, and there is the fear that some functions will write to the input data or write to control variables that they should not have access to. I also need to reduce memory copies and the like due to limited memory on each micro.
I'm trying to make a Quiz program based on C++'s Data File Handling capablities. I've attached the code in .txt file and I wonder why I'm getting the error identifier bScience cannot have a type qualifier?
In the below code I'm having trouble calculating the algebraic equation on the line marked with &&&. I attempt to calculate it both within the member function Energy(x) and within find_kin_en(x), but in the latter I find the result equal to zero, which is wrong and disagrees with the correct value calculated in Energy(x). I think the problem might be having multiple nested member functions, i.e. operator() calls Energy(x) which calls find_kin_en().
#include "/u7/tolsma/Numerical_Recipes/nr_c304/code/nr3.h" // these are numerical recipes libraries, not important for the problem below I believe. #include "/u7/tolsma/Numerical_Recipes/nr_c304/code/mins.h" #include "/u7/tolsma/Numerical_Recipes/nr_c304/code/mins_ndim.h"
My assignment is to handle rational numbers of different denominators...
Develop rational number class that can •add •subtract •multiply •divide •reduce to simplest form Your class must be able to handle rational numbers of different denominators
This is the errors I am getting
error C4716: 'Rational::addition' : must return a value error C4716: 'Rational::multiplication' : must return a value error C4716: 'Rational::division' : must return a value error C4716: 'Rational::subtraction' : must return a value
I am writing a program which is using SDL library. I have two different classes which one of them is Timer Class and the other is EventHandling Class.
I need to use some member functions and variables of Timer in some Eventhandling Class member functions, Although I want to define an object of Timer in int main {} and relate it to its member function that has been used in Eventhandling member function in order that it becomes easier to handle it, I mean that I want to have for example two objects of timer and two objects of Eventhandling class for two different users.
I do not know how to relate an object of a class from int main{} to its member function which is being used in another class member function.