|
to clone an object is a java (or .NET) naming. in C++, where variables are not necessarily handled by reference, everything is done in the constructor (if it is well written of course )
so, something like the following should work :
Stream* s1 = ;
Stream s2 = new Stream(*s1);
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
I need help with my orderedlist.cc. In the end we are to produce a sorted word dictionary which will reads words in and output them in sorted form. This is just two of the files. I also have KeyValue.h, KeyValue.cc staticHTable.h, staticHTable.cc.
This is the provided h file given:
<br />
include <string><br />
#include "KeyValue.h"<br />
using namespace std;<br />
<br />
class OrderedList<br />
{<br />
public:<br />
OrderedList();
~OrderedList();
<br />
<br />
void insert( string word, string definition);<br />
<br />
<br />
const string inspect( string w ) const;<br />
<br />
bool isIn( string w ) const;<br />
<br />
bool isEmpty() const;<br />
<br />
void printEntry() const;<br />
<br />
public:<br />
KeyValue* head;<br />
};<br />
the cc file of it of which i have done some but struggling to do and understand the next bits!
<br />
#include <iostream><br />
#include <stddef.h><br />
#include "OrderedList.h"<br />
#include <string> <br />
<br />
using namespace std;<br />
<br />
KeyValue::KeyValue()<br />
{<br />
word = "\0";<br />
definition = "\0";<br />
next = NULL;<br />
}<br />
<br />
OrderedList::OrderedList()<br />
<br />
{<br />
head = NULL;<br />
}<br />
<br />
OrderedList::~OrderedList()<br />
{<br />
KeyValue* Current;<br />
KeyValue* it;<br />
<br />
it = head;<br />
while (it != NULL);<br />
<br />
{<br />
Current = it;<br />
it = it->next;<br />
delete Current;<br />
}<br />
}<br />
<br />
bool OrderedList::isEmpty() const<br />
{<br />
return head == NULL;<br />
}<br />
<br />
<br />
<br />
void OrderedList::insertBefore(const int newval, const int val)<br />
{<br />
KeyValue* p = new KeyValue;<br />
KeyValue* iterator = NULL; <br />
KeyValue* previous = NULL;<br />
<br />
p->word = newval;<br />
p->next = NULL;<br />
if (isEmpty())<br />
{<br />
cout << "List is empty\n";<br />
}<br />
else<br />
{<br />
for (iterator = head; iterator != NULL; iterator = iterator->next)<br />
{<br />
if (iterator->word == val) <br />
{<br />
if (iterator == head)<br />
{ <br />
head = p;<br />
}<br />
else<br />
{<br />
previous->next = p;<br />
}<br />
p->next = iterator;<br />
break;<br />
}<br />
else <br />
{<br />
previous = iterator;<br />
}<br />
}<br />
}<br />
}<br />
<br />
void OrderedList::printEntry() const<br />
{<br />
if (isEmpty())<br />
{<br />
cout << "List empty" << endl;<br />
}<br />
else
{<br />
KeyValue* p = NULL;<br />
for (p=head; p!=NULL; p=p->next)<br />
{<br />
cout << p->word << endl; <br />
}<br />
}<br />
}<br />
i need help in doing the const string inspect( string w ) const; function and bool isIn( string w ) const becasue i really dont know how to do this to matter how much i have a go at it. Also what would be helpful if someone could also check that i have done everything right in the cc coding becasue i have got some errors for it! Also do i need to include a main program for this. I can also provide the KeyValue.h and KeyValue. files if needed.
Thanks (Hopefully you will be able to help me on this cos i have been finding this very very hard.
|
|
|
|
|
Hi! I am a bit stumped..
I am a fairly new MFC programmer, and I am creating a form-based application with mulitiple tabs. I am using the CTabCtrl class to create the tabs. Those work great, and I can even switch back and forth between tab views when I click on the tabs, but when I resize the main window the tabs have a static size. I would love it if the tabs also resized. Each of my tabs are dialogs.. I am not sure if that matters.
I did create an ON_WM_SIZE() message handler, and when the main window is resized, the breakpoint stops there. So I figure I need to add code in this message handler somewhere:
<pre)
void cresizeview::onsize(uint="" ntype,="" int="" cx,="" cy)
{
="" if(ntype="" !="SIZE_MINIMIZED" &&="" (cx=""> 0) && (cy > 0))
{
// Resize tabs????
}
CFormView::OnSize(nType, cx, cy);
}
I know I also need to somehow obtain a pointer to my tabs which are within the view. Not sure how to do that. One of the many reasons I am so confused.. any help would be greatly appreciated!!
~Sheri
|
|
|
|
|
|
Hi,
How do I overload operator[] such that when i have the following statement in my program:-
a[10][20][3]; //any number of dimensions
The requirement is :
1) i should be able to accept the values in the subscript operators.
2) With those values, i should be able to allocate memory dynamically in my operator[] function.
3) the function should be able to accept variable number of arguments(here, a[3][2][3][2]; has four arguments....namely a,3,2,3,2).
please help me.
PK
|
|
|
|
|
an alternative to such a behavior is to overload the operator () instead, but i conceed, you will have a fixed number of dimension...
i don't think overloading the operator [] is possible for such a thing, because look :
if you have myType t[10];
[] will work on a myType array (every thing fine so...)
but with myTpe t[10][20];
the second [] will work on a myType[10] array... now, everything goes hard because you would have to overload as many versions of the [] as you want for the first dimension !!!
imagine myType[10][20][30];
the 3rd [] works on a myType[10][20] array !!!!!!
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
toxcct wrote: i don't think overloading the operator [] is possible for such a thing,
Why? This will work for infinite dimensions.
class A
{
public:
A operator [](int index)
{
A a;
return a;
}
};
Of course, it'll be tough to code the body of the function, as you won't know which dimension you are in.
Oh, in myType[10][20], the second dimension operates on whatever was returned by the first [], so it's not really overloading for myType[10].
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
-- modified at 4:35 Saturday 5th November, 2005
|
|
|
|
|
For a 2-D situation the easiest thing to do is something like this:
<code>
Array of arrays of ints
typedef vector<vector<int> > CMultiIntArray;
void TraceDynamicArray(const unsigned int rows, const unsigned int columns)
{
CMultiIntArray aTest;
// Allocate number of rows
aTest.resize( rows );
// For each row
for (int row = 0; row < aTest.size(); row++)
{
// Allocate number of columns
aTest[row].resize( columns );
// For each column
for (int column = 0; column < aTest[row].size(); column++)
{
// Assign a value
aTest [row] [column] = 10 * row + column;
// Trace it
cout << aTest [row] [column] << "\t";
}
cout << "\n";
}
}
// Example usage: Standard C++ Library version
int main(int argc, char* argv[])
{
TraceDynamicArray(3,5);
return 0;
}
// For rows = 3, columns = 5, produces output...
// 0 1 2 3 4
// 10 11 12 13 14
// 20 21 22 23 24
</code>
Then you can do something similar for higher dimensions. But you have to define the dimensions upfront.
Kevin
|
|
|
|
|
I have a question. I wrote and array of 5 structs into a binary file. I need to be able to go to a specific position in a binary file and overwrite that struct with another. I have tried it but when i go to overwrite the struct the ones before it all the data is screwed up.Can anyone help me on how to overwrite a specific person in the file.
struct PERSON
{
int age;
int weight;
char name[25];
};
void write_names() //WRITES 5 PEOPLE TO THE FILE
{
ofstream out;
PERSON p[5];
int ct;
p[0].age = 1;
p[0].weight = 1;
strcpy(p[0].name, "Num_1");
p[1].age = 2;
p[1].weight = 2;
strcpy(p[1].name, "Num_2");
p[2].age = 3;
p[2].weight = 3;
strcpy(p[2].name, "Num_3");
p[3].age = 4;
p[3].weight = 4;
strcpy(p[3].name, "Num_4");
p[4].age = 5;
p[4].weight = 5;
strcpy(p[4].name, "Num_5");
out.open("file.dta", ios::binary);
for (ct=0; ct<5; ct++)
out.write((char*)& p[ct], sizeof(p[ct]));
out.close();
}
void show_names() //SHOW ALL THE PEOPLE IN THE FILE
{
ifstream f;
f.open("file.dta", ios::binary);
PERSON p[10];
int ct;
int num = 0;
while(!f.eof())
{
f.read((char*)& p[num], sizeof(p[num]));
num++;
}
num--;
for(ct=0; ct
|
|
|
|
|
you need to use ios::binary|ios::_Nocreate as the open mode when you do the open to replace the second person
|
|
|
|
|
Basically I have two programs... the first program as you to input a total number of variables you want... max of 8.. then it ask you for its value... after it does all that it ask you if you want to add subtract mult or divide... then once all that is done it out puts to a file of your choice(what you name it)
LOOKS LIKE
a 1
b 2
c 3
d 4
e 5
f 6
g 8
h 10
add
a b
sub
d e
mul
e a
div
c d
and so on.... my problem is in my second program im trying to read the values in the being able to read in the command add sub div or mul... i attempt while(!fin.eof()) and read in the opperation add,sub and so on then the 2 variables like a b c d e f and so on... then run a bunch of if statesments to test if they match and once it does it outputs the answer.. the i want it to go to the next line...and read in next opperation and 2 variables and compute but it usually fails...
heres sample code...
#include <iostream>
#include <fstream>
#include <iomanip>
//dynamic memory
using namespace std;
int main()
{
ifstream fin;
ofstream fout;
char filename[20];
int pause,x,y,z;
int int1,int2,int3,int4,int5,int6,int7,int8;
char char1,char2,char3,char4,char5,char6,char7,char8;
string opp1[x];
char aa[x];
char bb[x];
x=0;
cout <<"Please enter the filename that you created to store"<<endl;
cout="" <<"information="" in="" the="" first="" program.="" ex:="" c:\data.txt"<<endl;
="" cin="">>filename;
fin.open(filename, ios::in);
cout<<"This is my awesome program:"<<endl;
if="" person="" doesnt="" enter="" all="" 8="" variables="" then="" they="" fill="" with="" zeros
="" int1="0;
" int2="0;
" int3="0;
" int4="0;
" int5="0;
" int6="0;
" int7="0;
" int8="0;
" char1="0;
" char2="0;
" char3="0;
" char4="0;
" char5="0;
" char6="0;
" char7="0;
" char8="0;
" fin="">> char1 >>int1;
fin >> char2 >>int2;
fin >> char3 >>int3;
fin >> char4 >>int4;
fin >> char5 >>int5;
fin >> char6 >>int6;
fin >> char7 >>int7;
fin >> char8 >>int8;
cout <<char1 <<"=" <<int1 <<endl;
cout <<char2 <<" =="" "="" <<int2="" <<endl;
="" cout="" <<char3="" <<int4="" <<char5="" <<int6="" <<char7="" <<int8=""
="" while(!="" fin.eof())
="" {
="" fin="">> opp1[x];
//cout <<opp1[x] <<endl;
="" fin="">>aa[x];
//cout <<aa[x]<<" ";
="" fin="">>bb[x];
//cout <
|
|
|
|
|
Hello,
i a little newbie to C++. So sorry for some stupid questions.
The following scenario:
We have a java application running on 200 pcs in a network enviroment. If a user starts the app the complete jre has to be loaded from a mounted network volume. This took about 20 to 40 sec. We cannot change this...
So currently i'm trying to write a splash screen which is showing the user that something is going on.
The splash screen is implemented. Now my question. Is there an easy way to lauch a jar as a process from c++ in that way that the splash screen waits until the java app is started?
Are ther tutorials in the web available?
Thanks for any help.
Regards,
Carsten
University of Konstanz
|
|
|
|
|
if you have a console command that can be launching your java app, you could so easily call
ShellExecute(NULL, "open", "myCommandLine here", NULL, NULL, SW_SHOWMINIMIZED);
or
system("myCommandLine here");
TOXCCT >>> GEII power [toxcct][VisualCalc]
-- modified at 5:46 Wednesday 2nd November, 2005
|
|
|
|
|
Hi,
to launch my java app this works... but how do i wait then with my c++ app until the app/process is really completed?
Thanks for any help.
Regards
Carsten
|
|
|
|
|
i'm not sure, but i think of deporting this code into a worker thread... see if you don't find some infos on the web on that subject.
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
|
Hi all,
I have a very important problem. that How to judge a string encoding is euc, sjis, ascii or others?
I must alway kown a string encoder, and I must convert it to other encoder.
so first, I must know the encoder of a string.
thank you very much.
thanks a lot.
---------------------------
Vc++.net Managed
|
|
|
|
|
a function that judge a string is ASCII or EUC, SJIS, JIS was welcome.
thanks.
----Junyin.Wu
|
|
|
|
|
there is no way to know such an information programatically... sorry
there is only one thing you can know : if the length of the string have an odd number of bytes, it cannot be UNICODE
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
try IMultiLanguage2::DetectCodepageInIStream
http://blog.joycode.com/jiangsheng
http://blog.csdn.net/jiangsheng
http://bloglines.com/public/jiangsheng
Command what is yours
Conquer what is not
---Kane
|
|
|
|
|
thank you very much,
and we are trying.....
|
|
|
|
|
Of course it can be Unicode with an odd number of bytes. In Unicode text encoded with UTF-8, the characters are composed of byte sequences of sizes between 1 and 4 bytes, depending on the character. Perhaps you meant UTF-16 or UTF-32?
--
The Blog: Bits and Pieces
-- modified at 1:40 Tuesday 1st November, 2005
|
|
|
|
|
|
Hi,
Being relatively new to socket programming, I need some assistance in sending and receiving data over a TCP connected socket. I'm familiar with using send and recv commands to send and recv buffered character data, but what about if I want to send and recv data formatted within a structure? For example,
<code>
main ()
{
struct {
int data1;
double data2;
bool indicator;
}msg;
// initialize data
msg.data1 = 0;
msg.data2 = 5.8;
msg.inidicator = false;
// send data
.....
// receive data
.....
}
</code>
Are the send and recv commands the right ones to use for this type of information to send and receive data over a TCP connected socket or are there other commands that are better suited for this. When I use the send(socketfd, (char *)&msg, 0), it "appears" to work, but when receiving the data using recv(socketfd, (char *)&msg, 0), it returns with a -1.
Thanks in advance for any help.
-Martin
NB: The commands must work on both the Windows and UNIX side, so Windows specific commands wouldn't work.
|
|
|
|
|
you are sending 0 bytes. you need to give it a size that your are sending. You also need to give a size when you recv.
It would work best if you just used sizeof(msg)
|
|
|
|
|