|
Followig the local variables using breaks most of the arrays are initialized ok, but their values change (to cxx0030:Error:expression can not be evaluated)latter when they are not being called. I have also noticed that a variable used in a for loop changed when it should not have it went from 116 (which is what it should be) to 116547629.
Can you think of anything that could cause these changes?
simaneal
|
|
|
|
|
simaneal wrote:
I have also noticed that a variable used in a for loop changed...to 116547629.
Nothing special about that number.
simaneal wrote:
Can you think of anything that could cause these changes?
Yes, something like:
for (int x = 0; x < 117; x++)
{
int &r = x;
int *p = &x;
r = 116547629;
*p = 116547629;
}
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
I am tring to fill the buffer with text then output that information to a text file. Then line
int nBytesToWrite = FillBuffer(1024);
Gives me an error "FillBuffer: identifier not found"
Am I missing a header? I am using C++ .net to compile.
|
|
|
|
|
Is FillBuffer() a method of BinaryReader ? If so, where's the object at?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Here is the code for my prog.
#include <iostream>
#include <iomanip>
#include <fstream>
#include "afx.h"
using namespace std;
int main(int argc, char* argv[])
{
int nSizeLimit = 1000;
int nBytesWritten = nSizeLimit + 1;
CFile outFile;
while(int i=0<10000)
{
if(nBytesWritten > nSizeLimit)
{
CString strFileName;
strFileName.Format("LittleFile%d.txt", nBytesWritten++);
if(outFile.m_hFile != CFile::hFileNull)
outFile.Close();
outFile.Open(strFileName, CFile::modeWrite | CFile::shareDenyWrite);
nBytesWritten = 0;
}
char buf[512];
int nBytesToWrite = FillBuffer(1024);
if(nBytesToWrite == 0)
break;
outFile.Write(buf, nBytesToWrite);
nBytesWritten += nBytesToWrite;
}
return 0;
}
|
|
|
|
|
Andrew Admire wrote:
while(int i=0<10000)
What is the purpose of this? Initialize i and compare it to 10000 in two separate statements like:
int i = 0;
while (i < 10000)
... That aside, the variable i is never incremented.
Andrew Admire wrote:
outFile.Open(strFileName, CFile::modeWrite | CFile::shareDenyWrite);
What if the file does not already exist? Don't you want to create it, too?
Andrew Admire wrote:
char buf[512];
What does this variable do? It's not being assigned anything.
Andrew Admire wrote:
int nBytesToWrite = FillBuffer(1024);
I already asked about FillBuffer() . You are using it incorrectly. Why is it even there?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
This is a sample code someone gave me. It should create multiple files. So, for the fillbuffer part... I have no idea. The char buf array, I think it holds the words before sending it to file. As for the file... yes if it does not exist I would like to create it.
|
|
|
|
|
Andrew Admire wrote:
The char buf array, I think it holds the words before sending it to file.
Where do these words come from?
Andrew Admire wrote:
As for the file... yes if it does not exist I would like to create it.
Then you'll also need to use CFile::modeCreate .
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
I'm trying to create a LM database using text files.
|
|
|
|
|
I'm not familiar with an LM database. Is that:
London Medical
Literary Machine
List Manager
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
|
hi, i have two classes in my program: class1 and class2. if i want to have them both include pointers to each other, how do I do that? one class must always be declared before the other. here is some example code::
main.cpp
#include "class1.h"
void main() {
class1 test;
}
class1.h
#pragma once
#include "class2.h"
class class1 {
private:
class2 *child1;
class2 *child2;
public:
class1() {
child1 = new class2();
child1->Init();
child2 = new class2();
child2->Init();
}
};
class1.cpp
#include "class1.h"
class2.h
#pragma once
#include "class1.h"
class class2 {
private:
class1 *parent;
public:
void Init(class1 *the_parent) {
parent = the_parent;
}
};
class2.cpp
#include "class2.h"
Here is a snapshot of compiler output:
Compiling...
class2.cpp
class1.h(5) : error C2143: syntax error : missing ';' before '*'
class1.h(5) : error C2501: 'class1::class2' : missing storage-class or type specifiers
class1.h(5) : error C2501: 'class1::child1' : missing storage-class or type specifiers
class1.h(6) : error C2143: syntax error : missing ';' before '*'
class1.h(6) : error C2501: 'class1::class2' : missing storage-class or type specifiers
class1.h(6) : error C2501: 'class1::child2' : missing storage-class or type specifiers
main.cpp
class2.h(5) : error C2143: syntax error : missing ';' before '*'
class2.h(5) : error C2501: 'class2::class1' : missing storage-class or type specifiers
class2.h(5) : error C2501: 'class2::parent' : missing storage-class or type specifiers
class2.h(7) : error C2061: syntax error : identifier 'class1'
class1_1.cpp
class2.h(5) : error C2143: syntax error : missing ';' before '*'
class2.h(5) : error C2501: 'class2::class1' : missing storage-class or type specifiers
class2.h(5) : error C2501: 'class2::parent' : missing storage-class or type specifiers
class2.h(7) : error C2061: syntax error : identifier 'class1'
one class's signature must be declared before the other, but they both reference each other.. how can this be done?
|
|
|
|
|
class1.h
#pragma once
#include "class2.h"
class class2;
class class1 {
private:
class2 *child1;
class2 *child2;
public:
class1()
{
child1 = new class2();
child1->Init();
child2 = new class2();
child2->Init();
}
};
Cleek | Image Toolkits | Thumbnail maker
|
|
|
|
|
thanks so much! first time i got an answer in a forum in only 2 minutes
|
|
|
|
|
You need to use forward declarations.
Try this:
<br />
#pragma once<br />
<br />
class class2;<br />
<br />
class class1<br />
{<br />
private:<br />
class2* child1;<br />
class2* child2;<br />
<br />
public:<br />
class1()<br />
{<br />
child1 = new class2(this);<br />
child2 = new class2(this);<br />
}<br />
};<br />
<br />
#pragma once<br />
<br />
class class1;<br />
<br />
class class2<br />
{<br />
private:<br />
class1* parent;<br />
<br />
public:<br />
class2(class1* the_parent) : parent(the_parent)<br />
{<br />
}<br />
};<br />
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
that appeared to solve my problem, but now i have a new one.
i get error C2512, no default constructor available, but there is a public constructor clearly defined with no parameters for both classes. this error occurs in the constructor for struct1. here is the code:
main.cpp
#include "class2.h"
void main() {
struct1 *config;
config->item = new class2();
config->item->Init(config);
}
struct1.h
#pragma once
#include "class2.h"
class class2;
struct struct1 {
private:
class2 *item;
public:
struct1() {
item = new class2(); /* ERROR OCCURS HERE while
compiling main.cpp and class2.cpp */
}
};
class1.h
#pragma once
class class1 {
public: class1(){}
};
class2.h
#pragma once
#include "class1.h"
#include "struct1.h"
struct struct1;
class class2 : public class1 {
private:
struct1 *cfg;
public:
class2() {}
void Init(struct1 *data) {
cfg = data;
}
};
struct1.cpp
#include "struct1.h"
class1.cpp
#include "class1.h"
class2.cpp
#include "class2.h"
|
|
|
|
|
The way you are mixing #includes and forward declarations is wrong. For example, take a look at what the compiler is seeing when you ask it to compile class2.cpp
- finds an include for "class2.h", so it goes for it.
- finds an include for "class1.h", so it goes for it.
- compiles the declaration for class1. Nothing else in this file, so it returns to class2.h
- finds an include for "struct1.h", so it goes for it.
- finds an include for "class2.h", but it's already started processing that file, and noted a "pragma once" directive, so it ignores this include.
- finds a forward declaration for class2, so it says to itself "I now know class2 is a class, even if I still don't know all the details"
- starts compiling the declaration for struct1. Finds the declaration of "item" as a pointer to a "class2". At this point, the compiler only needs to know wether the type of "item" is valid, and how much space it takes to store it. It does know the type is valid because of the forward declaration. And it does know how much space is needed for "item", because all pointers are the same size. Compilation goes on.
- It now reaches the line with "new class2()" in it, so it needs to create a call to some constructor of class2 with no parameters. The problem is it hasn't actually seen the complete declaration of class2 yet, so it doesn't know if such constructor exists
Reorganize your code as follows:
#pragma once
class class1
{
public:
class1();
};
#include "class1.h"
class1::class1()
{
}
#pragma once
#include "class1.h"
struct struct1;
class class2 : public class1
{
private:
struct1* cfg;
public:
class2();
void Init(struct1* data);
};
#include "class2.h"
class2::class2()
{
}
void class2::Init(struct1* data)
{
cfg = data;
}
#pragma once
class class2;
struct struct1
{
private:
class2* item;
public:
struct1();
};
#include "struct1.h"
#include "class2.h"
struct1::struct1()
{
item = new class2();
}
#include "class2.h"
#include "struct1.h"
void main()
{
struct1* config;
config->item = new class2();
config->item->Init(config);
}
I didn't actually compiled the above code, so it may still fail due to some typo, but I hope you get the idea.
--
jlr
http://jlamas.blogspot.com/[^]
|
|
|
|
|
ok thank you so much, my code compiles and runs now
|
|
|
|
|
Hi,
I am doing a project in vc++ win32...dialog based app.
I want display the content from a text file in a text box in my dialog.
say for eg. License agreement..
how do i do that.What the properties should I set for the text box.
Thanks a lot.
|
|
|
|
|
If it is a simple edit box (plain text) then use Object.SetWindowText(CString) .
You can use a LPCSTR pointer etc., a null terminated string etc.
For rich text it's a bit more difficult and involves callbacks etc., if so let me know and I will send a code sample.
Elaine
The tigress is here
|
|
|
|
|
Trollslayer wrote:
For rich text it's a bit more difficult
How so? SetWindowText() also works for rich edit controls.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
That works fine until you reach the buffer limit, tried it a couple of weeks ago.
After that you have to use StreamIn with a callback.
Elaine
The tigress is here
|
|
|
|
|
Trollslayer wrote:
That works fine until you reach the buffer limit...
Which is what?
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
It isn't specified, but in my was case just over 4KB (4196 bytes if i remember correctly). This is the buffer size passed over to the StreamIn callback function. I assume that WriteWindowText uses the same internal mechanism.
The tigress is here
|
|
|
|
|
You obviously did something wrong. A regular edit control can handle 64KB of text. A rich edit control can handle several MB of text. I just tried it with a 791KB text file (it's the biggest one I could find within a few seconds) and it worked fine.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|