C++ :: How To Exchange Strings In Field
Sep 29, 2013
I need exchange strings in field, but how to do that. For example:
{"Hi", "Hello", "Goodbye", "Morning"};
to
{"Hello", "Hi", "Goodbye", "Morning"};
I tried this, but it isn't working:
Code:
for(unsigned int k=0; k<slova[i].size();k++){
t = slova[i][k];
slova[i][k] = slova[i+1][k];
slova[i+1][k] = t;
}
View 7 Replies
ADVERTISEMENT
Apr 12, 2015
So I have this class
class DataBase
{
// Change the connection path here to your own version of the database
public SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)v11.0;AttachDbFilename=|DataDirectory|UberDatabase.mdf;Integrated Security=True;");
public DataBase()
{
}
}
And in the same namespace as this class I have a form that calls it like so:
DataBase dBase = new DataBase();
SqlCommand trythis = new SqlCommand("Register", dBase.con);
However, I'm getting the field initializer error on dBase.con. I'm not sure why, but when I call the database from another file (program.cs) it works fine this way.
View 8 Replies
View Related
Nov 6, 2014
I have written library in c++ for c++ application. Here, data exchange between library and client through structure. This structure has 20 members ( strings, integers, reals, pointers).
In some flows, library needs few members should get filled in the structure. for ex, application filled 3 integers information and passed to structure. But, in memory, whole structure is occupied.
I think, If library provides functions for every combination, then it would end up with lot of functions. I want to avoid that.
How to optimize data exchange between client and library? ( number of members may be filled sometimes 1, 2, 3, .. 20)
View 7 Replies
View Related
Mar 15, 2012
#include "vehicle.h"
...
void exchange(vehicle *&v1, vehicle *&v2) {
vehicle *tmp = v2;
v2=v1;
v1=tmp;
}
Is it right?
How about: void exchange(vehicle *v1, vehicle *v2){...}
What is the difference between *&v1 and *v1 ?
View 4 Replies
View Related
Jan 19, 2014
I am trying to iterate a matrix in order to exchange rows and columns element by element. Although the function that exchanges the rows has come out well, i don't seem to figure out how to do the same on columns.The columns switch for a matrix like
1 2 3
1 2 3
1 2 3
if i try to switch column 3 and 2,is:
1 3 2
1 3 2
1 2 3
Here are both of the functions:
void interchange_rows(int *p,int n,int r1,int r2){
int temp;
for(int i=0;i<n;i++){
temp=*(p+r1*n+i);
*(p+r1*n+i)=*(p+r2*n+i);
*(p+r2*n+i)=temp;
[Code] ......
View 1 Replies
View Related
Apr 8, 2014
Base class has an array, whose size is controlled by the derived class.
I can't use the STL and use a 2003 compiler, so things like std::vector and std::array are out. I also can't use dynamic memory allocation.
So I thought of a few options:
1.
template <int N> class myBaseClass { ... int array[N]; ... }
then class MyClass: public myBaseClass<8> ... etc ...
2.
have a int **array in the base and assign in the derived class.
3.
give the base some virtual methods such as int *getArray or even int &getInt for more safety.
View 6 Replies
View Related
Feb 16, 2013
I have a file which has records with 2 fields--one int and one float..what is the best way to sort it?
The sorting has to be based on the int field(the first field) (each time the program runs the file might end up with some hundreds of records).
View 13 Replies
View Related
Sep 11, 2014
I'm trying to write a simple program that extract the FAT information from a FAT32 virtual Hard Disk.I have the following structures regarding the FAT format:
Code:
//BOOT RECORD
typedef struct NF_BOOT_RECORD
{
unsigned char BS_jumpBoot[3]; //EB 58 90 = JUMP 58 NOP (Jumps to boot code). Also E9 is acceptable.
unsigned char BS_OEMName[8]; //Either MSWIN4.1 or mkdosfs
unsigned short BS_BytesPerSec; //Little endian. The size of a sector. 128,256,512,1024...
unsigned char BS_SecPerClus; //The number of sectors per cluster (1 CLUSTER = BPS*SPC BYTES)
unsigned short BS_RsvdSecCnt; //The boot sectors (this) are included. That makes at least 1.
}
[code]...
Everything seems to work fine. Mostly. The only problem, is that the program gives me the following output:BS_NumFATs shouldn't be 0. In fact, I've checked inside the structure memory, and the information seems correct. BS_NumFATs is 0x02, not 0x00 (It's the byte at offset 0x10, starting at 0x00).
I've checked the order of the structure fields, and their types, comparing them to the FAT specification given by Microsoft (File fatgen103.pdf), and it seems fine, unless I'm missing something. So I don't know why it gives 0 instead of 2, if I'm missing something.It's a Win32 program compiled with GCC version 4.4.0
View 3 Replies
View Related
Apr 21, 2014
I wrote a script that generates n random pixel positions and draws them to the screen. Works well. Now i tried to rotate them. Rotating does work too. But it does not work as i planned it.
paramters 'angle' and 'timestep' work somehow, but not as they should do. the function 'move' is supposed to rotate the pixelfield 'angle' degrees in a given direction, addicted to the 'timestep' parameter. 'timestep' is needed time for drawing in one single game loop.
angle_step = timestep * angle
// x
ppdPoint[i]->x =
pRotationPoint->x + cos(angel_step) * (ppdPoint[i]->x - pRotationPoint->x) - sin(angel_step) * (ppdPoint[i]->y - pRotationPoint->y);
// y
ppdPoint[i]->y =
pRotationPoint->y + sin(angel_step) * (ppdPoint[i]->x - pRotationPoint->x) + cos(angel_step) * (ppdPoint[i]->y - pRotationPoint->y);
rotation point is the middle of the screen. when i set angle to 10 it should rotate 10 degrees / second. Instead it's rotating very very fast and all stars are moving nearer to the center of the screen, so after x rounds there is just 1 pixel left in the middle of the screen. there is a kind of gravition.I'm working with SDL2. What I did find out:
FPS is <= 60, 'cause of the 'SDL_RENDERER_PRESENTVSYNC' flag. When i skip that flag, for any reason the 'gravition' would take more time. FPS is <= 1400 then, 'though i got a natural game loop (i hope):
while(pBuild->getExecuteFlag())
{
pBuild->draw();
pBuild->update(time_dif, pTimeWindow->TimeStampB);
time_dif = (pTimeWindow->TimeStampB - pTimeWindow->TimeStampA);
time_dif *= 0.001;
pTimeWindow->TimeStampA = pTimeWindow->TimeStampB;
pTimeWindow->TimeStampB = SDL_GetTicks();
pBuild->count_fps(pTimeWindow->TimeStampB);
}
So maybe (timestep * angle) isn't the right way?
View 13 Replies
View Related
Aug 8, 2014
I need writing a program in c++ that will get the input of 50 different users for the following the fields (surname, other names, sex, status, date of birth) and after entering the data for these 50 users, it will then output only the list of all FEMALE users who were registered...
#include <iostream>
#include <string>
using namespace std;
int main () {
string surname, other_names1, other_names2, status, sex, dob;
[Code] ....
I don't really know what to do next - all my attempts have not really given me the result I want.
View 19 Replies
View Related
Oct 30, 2014
I have a DateTime field on a database it looks like this :
2014-10-21 14:34:37.697
I want to use it, as is, in an UPDATE statement something like:
UPDATE PayrollRuns SET IsProcessed = 'True' WHERE Date_Time_Triggered = '2014-10-21 14:34:37.697'
I must have the exact date & time as that uniquely identifies the record.
The problem I'm having is getting it off the database and into an C# variable without it being changed.
I can get it into a string but it changes it becomes:
21/10/2014 14:34:37
I've got it in an object. I've tried:
string date_Time_Triggered = databasesRow["Date_Time_Triggered"].ToString();
//
//and
//
var date_Time_Triggered = databasesRow["Date_Time_Triggered"];
[Code] ....
View 3 Replies
View Related
May 2, 2012
class myCls{
int x;
};
and then I create:
myCls c1;
and now:
is there way that I go like: cout << c1;
not overloading << operator;
and it shows me a value of c1.x?
just wanna replace c1 with that value;
I need sth similar to indexer from c#.
View 1 Replies
View Related
Nov 27, 2014
I have a dynamic storage class based on a vector. The elements of this class shall be addressable via a string.
I have something like the following:
StorageClass* test = new StorageClass();
while(notEnd) {
test->setValue("name3", 3);
test->setValue("name2", 4);
[Code] ....
The Storage class is implement with a vector having to attributes per entry, the first one is name the second one is value. If the setValue function is called, Igo through the whole vector to find the correct item via the name and than i set the new value.
At the end of the loop i want to write out the data into a comma separated value file (*.csv). This shall be done generic by the writeLineToFile() function of the StorageClass.
As a want the columns in csv file to be sorted in a specific way a thought about a preInitalisation routine at the beginning of the program which builds a the vector with all possible entries as something like this in order to define a specific output order.
test->assign("name1");
test->assign("name2");
test->assign("name3");
So my outputfile should look like this:
name1;name2;name3;
5;4;3;
I now have 2 places in the code where i write down the "fieldnames".
I was wondering if there is a possibility to check if the fields called by the setValue function were first aranged in the vector by the assigned() function before or bettwer while compiling the programm.
I thought about MAKROS with #define XYZ and #ifndef XYZ #error to do though, but currently i reached a dead end and find no solution for my problem.
View 4 Replies
View Related
Mar 11, 2014
I am building a template for CodeBlocks, which pre-write some includes, the main skull and a header.
This header looks like that :
/**
* @Author Me
* @Description Brief description
* @Date ??
*/
I would like to put the current Date, just after the line @Date, is-it possible ? And if yes, it-is possible to put a field @FileName which copy the filename into the comment ?
View 2 Replies
View Related
Mar 26, 2013
I need to use an instance of an object in a header file. The object requires a lot of pre-computation to be created.
I want to assign it to a "static const *NAMEobject*" field in the .h file, once it has been created. I assume that it is better to create it in another file and somehow pass it into the .h file.
View 14 Replies
View Related
Sep 2, 2014
void Log_In() {
system("cls");
gotoxy(30, 30);
time_t now;
time(&now);
[Code] .....
How to produce a password field with asterisk ****** .....
View 1 Replies
View Related
Jan 16, 2012
I am experiencing some errors with my first c++ program. im getting some compilation errors that i cannot figure out.
In file included from w2.cpp:7:
Fraction.h:17: error: variable or field 'enter' declared void
Fraction.h:17: error: expected primary-expression before 'struct'
Fraction.h:18: error: variable or field 'display' declared void
and so on ..........
Code:
#include "fraction.h"
//using namespace std;
/*
int main() {
struct Fraction fraction;
cout << "Fraction Simplifier" << endl;
cout << "===================" << endl;
enter(&fraction);
[Code] .....
View 1 Replies
View Related
Dec 9, 2011
Code:
class T
{
enum E { }
struct S { }
interface I { }
delegate void D();
class C { }
}
[code]....
All of the above are possible except the constant field of a type that is a struct. I can see why the non-string reference types would default to the only literal expression they can represent - null - and if I'm not mistaken the default value of a struct is an instance of the struct with all its fields set to their default value, but why is it that a const struct field is not possible? is there a reason why or is it just the way c# was written? oh and by the way, what's the idea of allowing enum types to have a default constructor?
View 4 Replies
View Related
Mar 29, 2014
I'm creating a payroll program and here is my code
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define REPORTHEADING1 " Employee Pay Hours Gross Tax Net
"
#define REPORTHEADING2 " Name Rate Worked Pay Due Pay
}
[code]....
The errors I get are: variable or field PrintSummaryReport declared void in function voidPrintSummaryReport... cannot convert FILE to const car for argument to int printf(const char*...) which is for the following lines
Code:
printf(reportFile,REPORTLINEFORMAT1,fullName,payrate,regHours,gross,fedtax,
ssitax,netpay);
printf(reportFile,REPORTLINEFORMAT2,ovtHours,statetax,deferred);
View 7 Replies
View Related
Aug 26, 2014
I need a static hash table to keep track of all objects of a particular type that are instantiated in a Qt application but I have never used a template class as a static member object before and I can't seem to figure out how to initialize it. QHash is the hash table class that follows the template convetion:
template<class key, class data>
QString is probably self explanatory.
Example Header:
class MyClass {
...
private:
static QHash<QString, MyClass*> instanceTable;
}
Here is my source that doesn't compile.
Example Source
#include header.h
// using default constructor for table...
QHash<QString key, MyClass* instance> MyClass::instanceTable(); // gives Error below.
// Error in above line is "Declaration is incompatible with QHash<QString, Myclass*>"
I have tried doing it a number of different ways and none of them work. How do you initialize a static template object?
View 2 Replies
View Related
Sep 17, 2014
Why I am getting this error
error: variable or field createBinaryFile declared void
void createBinaryFile(std::fstream&, std::ifstream&);
View 2 Replies
View Related
Apr 25, 2013
I have to output a series of data, I have to control the width of parts of my data. like following:
double a[] = {1.0, 2.0, 3.0};
double b[] = {1.5, 2.5, 3.5};
ofsteam myfile("result.txt");
for(int i=0; i<3; i++) {
myfile.width(5);
myfile << i+1 << " : " << a[i] << " - " << b[i] << end;
}
I only want to fix the width of a[i], b[i], but let the rest to be output normally.
how I can make it?
View 5 Replies
View Related
Jan 3, 2013
In a numerically intensive code, I have a Cartesian vector class Vector3d which has the normal operator overloading and basic functions such as dot product, magnitude, etc. For simplicity, assume that it is not a templated class and its components are of type double.
I frequently need large 1-d arrays (e.g. stl vectors) of Vector3d. Two use-cases must be satisfied:
1) The trivial case in which the data are stored as stl vectors of Vector3d;
2) The more difficult case where the individual components are stored as stl vectors of double, and are not guaranteed to be contiguous in memory (so one cannot rely on "stride").
Assuming the array lengths are all identical, I'd like to be able to access both types in a single loop. The straightforward way for case 2) is to construct a temporary Vector3d from the three components (indexed with the loop index). However, I would prefer not to incur the overhead of the constructor.
Is it possible using template metaprogramming. Ideally I'd like a CompositeVector3d that inherits from Vector3d and is constructed with the component vectors, but can be dereferenced using the loop index in the same way as one would do with case 1.
I am not looking for the typical template metaprogramming utility of being able to operate on the entire array without explicit loops. I just want the syntactic "sugar" whereby CompositeVector3d and Vector3d act the same, plus the avoidance of the cost of the constructor. I am not averse to using an additional templated class (perhaps a Field or a View class) to access the basic storage in both case.
Is it possible to do this without using a full template metaprogramming utility?
View 1 Replies
View Related
Mar 28, 2014
I'm creating a payroll program and here is my code
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define REPORTHEADING1 " Employee Pay Hours Gross Tax Net
"
#define REPORTHEADING2 " Name Rate Worked Pay Due Pay
[code]....
View 14 Replies
View Related
Jun 13, 2014
I have this class:
class Excuse
{...
public string Description { get; set; }
public string Results { get; set; }
public DateTime LastUsed { get; set; }
public string ExcusePath { get; set; }
....}
[Code] ...
When I run it, I do get the messagebox popping up with the correct description, but then nothing happens. When I debug, I see the fields under the UpdateForm() method are set to null.
I'm guessing this happening because it is looking at the 'currentExcuse' that was declared in the form body. I thought however that redeclaring 'currentExcuse' in the method would overwrite this instance or am I wrong?
Do I need an array to make this work?
View 3 Replies
View Related
Dec 15, 2013
If we have to arrange large array structure, and we should also have to set a field which is the 'index' of elements in the structure array as:
typedef struct {
int index;
char [MENU_ELEMENTS_CHAR_MAX];
int value;
boolean enable;
} stc_MenuEntry;
const stc_MenuEntry GlobMenu[] =
[Code] ....
Suppose we have a lot of row like those written before: also many structured array , and we should mantain: inserting and deleting elements, without having to worry about index error insertion, what kind of preprocess should we choose to best perform the automatic field writing? Obviously we could set properly any array field as:
{
{START_INDEX, "menu_voice01",100, TRUE },
{NEXT_INDEX, "menu_voice02",100, TRUE },
{NEXT_INDEX, "menu_voice03",100, TRUE }
......
.....
};
Just to make the task easier, maybe to allow a 'program filter' to find and subtitute the field as required.
We should also put theese menu variable in RAM, and perform the field init, setting the index at run time, but if we want to save RAM (const attribute chosen) we must find a solution.
I thought about UNIX/LINUX OS filter like sed and awk which would maybe perform the task, before giving the source file to the building process, but I'm working on Windows environment and I don't know the appropriate tool to do this kind of work.
View 2 Replies
View Related