|
Thank you very much, it helps me.
|
|
|
|
|
after use CreateFile that return hFile
you can declare CFile m_fFile(hFile) & then use
m_fFile.Seek....
if you wanna work with in text mode you should use CStdioFile instead
of CFile .
|
|
|
|
|
how seprate client area of application from frame window in MDI?
is way is correct sepreate CChildFrame ???
alternative way i hear is :
create window with WS_OVERLAPPED! but when
i try this:
<br />
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)<br />
{<br />
cs.style |= WS_OVERLAPPED;<br />
if( !CMDIFrameWnd::PreCreateWindow(cs) )<br />
return FALSE;<br />
<br />
return TRUE;<br />
}<br />
there is nothing happen.
Best Regards.
MJM
|
|
|
|
|
mostafa_pasha wrote: seprate client area of application from frame window in MDI?
Please be more specific on what you want to do.
Best,
Jun
|
|
|
|
|
my project is MDI !
i have two view class , CStartPageView and CImageProcessingView !
first application execute OnDraw of CStartPageView because i create document
when OnFileNew fucntion run i create some object as CImagePorcessingView .when create new
page something that i use in CStartPageView::OnDraw show in client area of CImageProcessingView .
i mean every thing i draw in page has affect in another page!although the client area (to view class) is seperable.
<br />
m_pDocTemplate = new CMultiDocTemplate(<br />
IDR_ImageProcessingTYPE,<br />
RUNTIME_CLASS(CImageProcessingDoc),<br />
RUNTIME_CLASS(CChildFrame),
RUNTIME_CLASS(CImageProcessingView));<br />
if (!m_pDocTemplate)<br />
return FALSE;<br />
AddDocTemplate(m_pDocTemplate);<br />
<br />
m_pDocTemplateStartPage = new CMultiDocTemplate(<br />
IDR_ImageProcessingTYPE,<br />
RUNTIME_CLASS(CImageProcessingDoc),<br />
RUNTIME_CLASS(CChildFrame),<br />
RUNTIME_CLASS(CStartPageView));<br />
if (!m_pDocTemplateStartPage)<br />
return FALSE;<br />
AddDocTemplate(m_pDocTemplateStartPage);<br />
<br />
in OnFileNew:<br />
CDocument* pDoc = m_pDocTemplateStartPage->OpenDocumentFile(NULL);<br />
<br />
<br />
pDocTemplate->OpenDocument(BULL);<br />
<br />
|
|
|
|
|
mostafa_pasha wrote: in OnFileNew:
//create document that class view is CStartPageView
CDocument* pDoc = m_pDocTemplateStartPage->OpenDocumentFile(NULL);
// & for CImageProcessingView is
pDocTemplate->OpenDocument(BULL);
There are problems in your code. Try this in OnFileNew():
CImageProcessingDoc* pDoc = (CImageProcessingDoc*)m_pDocTemplate->OpenDocumentFile(NULL);
CFrameWnd* pNewFrame = m_pDocTemplateStartPage->CreateNewFrame(pDoc, NULL);
if (pNewFrame != NULL)
{
m_pDocTemplateStartPage->InitialUpdateFrame(pNewFrame, pDoc);
}
Best,
Jun
|
|
|
|
|
I am over-riding operator new [] so that when an array of "Objects" is created they contain information about adjacent items in the array. I am getting the following error....
c:\Visual Studio Projects\JLib\main.cpp(149): error C2661: 'Object<T>::operator new[]' : no overloaded function takes 3 arguments
The following code results in the above comilation error.
Object<double>* objects;
objects = new Object<double>[5]; // <- error occurrs here
delete [] objects;
If anyone knows what is going on I would very much appreciate an explanation.
Here is the relevant declarations and definitions...
#pragma once
#include <new>
using namespace std;
template <typename T> class Object{
public:
//CONSTRUCTORS ETC ETC ETC
void* operator new[](size_t size) throw(bad_alloc);
void* operator new[](size_t size,const nothrow_t&) throw();
void operator delete[](void* ptr) throw();
void operator delete[](void* ptr,const nothrow_t&) throw();
//OTHER STUF
};
template <typename T> void* Object<T>::operator new[](size_t size) throw(bad_alloc){
Object<T>* data = 0;
if ( (data = ::operator new[](size){
//ommitted for brevity
}
return data;
}
template <typename T> void* Object<T>::operator new[](size_t size,const nothrow_t&) throw(){
Object<T>* data = 0;
if ( (data = ::operator new[](size,const nothrow_t&)) ){
//ommitted for brevity
}
return data;
}
template <typename T> void Object<T>::operator delete[](void* ptr) throw(){
::operator delete [] (ptr);
ptr = 0;
}
template <typename T> void Object<T>::operator delete[](void* ptr,const nothrow_t&) throw(){
::operator delete [] (ptr,const nothrow_t&);
ptr = 0;
}
|
|
|
|
|
With GCC, the only error I get in your code is caused by the following (in bold):
template <typename T> class Object{
public:
void* operator new[](size_t size) throw(bad_alloc);
void* operator new[](size_t size,const nothrow_t& nt) throw();
void operator delete[](void* ptr) throw();
void operator delete[](void* ptr,const nothrow_t& nt) throw();
};
template <typename T> void* Object<T>::operator new[](size_t size) throw(bad_alloc){
Object<T>* data = 0;
if ( (data = ::operator new[](size){
}
return data;
}
template <typename T> void* Object<T>::operator new[](size_t size,const nothrow_t& nt) throw(){
Object<T>* data = 0;
if ( (data = ::operator new[](size, nt)) ){
}
return data;
}
template <typename T> void Object<T>::operator delete[](void* ptr) throw(){
::operator delete [] (ptr);
ptr = 0;
}
template <typename T> void Object<T>::operator delete[](void* ptr,const nothrow_t& nt) throw(){
::operator delete [] (ptr, nt);
ptr = 0;
}
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Hi,
I have problems reading values from a text file into an array. The first problem is reading the data from the file and the other is about data type conversion.
The values in a textfile are arranged vertically, like in a column:
0
1
0
1
1
0
0
1
.
. and so on. There is only 1 vertical column of numbers in the textfile.
I used a loop below to read the values from the file into an array:
while( inClientFile >> values) //inClientFile is an ifstream object.
cout<<.......<
|
|
|
|
|
See this response.
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
I'm having problems reading in line by line.
at the moment i have 2 and 3 in a text file sperated by a line. eg:
2
3
I am using the code below to read from the file...
<br />
while (PrimeFile.eof() == false && PrimeNumbers.size() < size){<br />
temp.clear();<br />
<br />
getline (PrimeFile,temp);<br />
<br />
tempInt = atoi(temp.c_str());<br />
<br />
<br />
<br />
PrimeNumbers.push_back(tempInt);<br />
<br />
<br />
}<br />
When the loop goes around once 2 goes into the int and is subsequently going into the vector PrimeNumbers. When it goes around again it reads 32 into the int.
Anyone know how i can get it so that it reads through the file one line at a time?
|
|
|
|
|
Since you are reading in numbers that are delimited by whitespace, you can use the following code:
while (PrimeFile.eof() == false && PrimeNumbers.size() < size)
{
int newPrimeNumber = 0;
PrimeFile >> newPrimeNumber;
PrimeNumbers.push_back(newPrimeNumber);
}
Alternatively, you can avoid writing your own loop altogether:
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <iterator>
using namespace std;
int main()
{
ifstream fin;
vector<int> MyVector;
fin.open("test.txt");
copy(istream_iterator<int>(fin), istream_iterator<int>(), back_inserter(MyVector));
fin.close();
copy(MyVector.begin(), MyVector.end(), ostream_iterator<int>(cout, " "));
}
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Hi,
I have some code which loads a char[] into memory from the source txt file,
Example
ifstream inn;
char text[20];
char text2[10];
inn.open("test.txt");
inn >> text; inn >> text2;
cout << text; cout << text2;
inn.close();
the text file contains
test and test
test
My problem is that this code only loads each word, seperated by a space in order. I want it to load it in order based on a new line.
Any ideas?,
thanks
Fred
|
|
|
|
|
FredrickNorge wrote: My problem is that this code only loads each word, seperated by a space in order. I want it to load it in order based on a new line.
The opeartor>> will stop when it gets to any whitespace. To get an entire line, use getline instead.
ifstream inn;
char text[20] = {0};
char text2[10] = {0};
inn.open("test.txt");
inn.getline(text, 19);
inn.getline(text2, 19);
cout << text; cout << text2;
inn.close();
Alternatively, you can use another version of getline that takes a string argument:
ifstream inn;
string text = "";
string text2 = "";
inn.open("test.txt");
getline(inn, text);
getline(inn, text2);
cout << text.c_str(); cout << text2.c_str();
inn.close();
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
thanks!, exactly what i needed.
Fred
|
|
|
|
|
Hello,
What is the difference between 'TRUE' and 'true'
BOOL IsYes;
IsYes = TRUE;
IsYes = true;
Does TRUE and true give different results?
Thanks.
Fortitudine Vincimus!
|
|
|
|
|
BOOL is defined as typedef LONG in Visual C++ libraries
TRUE is defined as #define 1
bool is built-in data type supported in C/C++ and true. This value has 1 byte in length while BOOL has 4 bytes in a 32 bit system
-Sarath.
The more you can dream the more you can do - Michael Korda"
|
|
|
|
|
Tara14 wrote: Does TRUE and true give different results?
no. they will both set IsYes to 1
|
|
|
|
|
TRUE is a #define that Microsoft's header files defines to 1. true is a built-in value for a bool that is equal to 1 (or rather, !false ).
It makes a little more sense when you look at the differences in the datatypes. BOOL is a typedef (or #define depending on the version of the header files) for an unsigned int (that is, it is 4 bytes in size). bool is a C++ standard type that is 1 byte in size (but easily can be represented by 1 bit).
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
TRUE is actually an int , because defined like this :
typedef enum {
FALSE = 0,
TRUE
} BOOL;
on the other side, bool is from the native language...
|
|
|
|
|
The important difference is between BOOL and bool . With BOOL , any non-zero value (not just TRUE ) is "true". This is the reason for the rule about never comparing a BOOL for equality with TRUE .
bool only has two possible values (true and false ).
|
|
|
|
|
If I understand correctly, if I declare a variable as
BOOL IsYes; then I can write a statement
if (IsYes == TRUE){....}
otherwise:
bool IsYes; if (IsYes == true) {...}
The confusion arose when I declare the variable as
BOOL IsYes; then, I wrote
if (ISYes == true) {..}
On compiling, I got the following warning:
warning C4805: '==' : unsafe mix of type 'int' and type 'const bool' in operation
Fortitudine Vincimus!
|
|
|
|
|
Tara14 wrote: if (IsYes == TRUE){....}
It's safer to do this :-
if(IsYes != FALSE){...}
|
|
|
|
|
Tara14 wrote: BOOL IsYes;
if (IsYes == TRUE){....}
Well, you can write that, but that's exactly what you should not do. As I just explained, TRUE is not the only value for a BOOL that means "true". The clearest (and correct) way to test a boolean for truth is simply:
if (IsYes) { ... }
|
|
|
|
|
Tara14 wrote: if (IsYes == TRUE){....}
You could write it that way, but it is much safer to write it like:
if (FALSE != IsYes)
The constant is first to avoid typographical errors (tracking down bugs when you type if (IsYes = FALSE) is a royal pain when you have large projects).
And testing against FALSE for BOOL variables is safer than testing against TRUE since TRUE is equal to 1, but a boolean expression is simply !FALSE (that is, anything other than 0).
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|