|
Hi,
Your formatting was not clear. However I guess it.
Yes, I know it is the problem of Yuwen Zhou.
But what I said, I repeat.
No man, its possible to define template function in cpp files
Does It can't be?
Best Regards
Raj
|
|
|
|
|
I found in Msdn this one
_mkdir( "\\temp") (header direct.h)
but it doesnt create me folder :/
my whole code
int rows = 10;
ofstream myfile;
CString str;
CString str2;
str.Format( _T( "%d") , rows);
str2= "\\Top "+str+" Files";
str = "Top "+str+" Files.txt";
if ( _mkdir( "\\temp") )
{
str2 = str2+str;
myfile.open (str2);
myfile << print;
myfile.close();
print = print+"\n Sas pliroforoume oti dimiourgi8ike arxeio me onoma \""+str+"\"\nsto fakelo pou exete kai ta ipolipa.\n";
}
|
|
|
|
|
The windows API CreateDirectory() or _mkdir (which uses CreateDirectory() on Windows builds)
will do it.
_mkdir returns 0 if the directory was created.
Mark
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
Hey guys, I have a line of code here that I am just stumped on.
All of my code for this project worked when compiled under VC++6.0 pro.
For some reason, creating of a new project and inclusion of the .cpp and .h files isn't enough to make it work on visual c++ 2005 (express).
Here is the line
magiitr = &Player1.Magi[mage1];
magiitr is defined as:
vector <Mage>::iterator magiitr;
Player1 is defined globally as:
player Player1;
It is a class of my own design.
Player1.Magi is of type std::vector<mage> player::Magi .
Player1.Magi[mage1] is an array. mage1 is an int.
So this is calling the instance of the mage class in Player1.Magi[1] assuming mage1 equates to 1.
I get a compiler error of c:\nehe\magi\magination\magination.cpp(857) : error C2679: binary '=' : no operator found which takes a right-hand operand of type 'Mage *__w64 ' (or there is no acceptable conversion)
If I remove the & and make it
magiitr = Player1.Magi[mage1];
I get the error:
c:\nehe\magi\magination\magination.cpp(857) : error C2679: binary '=' : no operator found which takes a right-hand operand of type 'Mage' (or there is no acceptable conversion)
If I rewrite it to:
*magiitr = Player1.Magi[mage1];
I do not get any compiler errors anymore, but I'm worried about segmentation faults. The code is still broken at this point to determine if this fixed it, but it's nice that I'm not getting any compiler errors.
I'd like to know why a simple change of &Player to *magiitr would change anything. magiitr=&Player sets the magiitr's value to the address of the player1.magi array.
*magiitr = Player1.Magi[mage1] sets the derefereced case of magiitr to the data stored in Player1.Magi[mage1]. I think.
The real kicker is that this worked once, but not now. Any ideas?
|
|
|
|
|
Kataric wrote: magiitr = &Player1.Magi[mage1];
Assuming an iterator is a pointer, is allowed in VC6, but that is wrong. VC2002 was the first to fix this problem.
Kataric wrote: The real kicker is that this worked once, but not now. Any ideas?
The core issue is that your code is non standard, and VC6 really sucked.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Is my solution correct?
Using *magiitr = &Player1.Magi[mage1]; instead.
How would I be able to standardize my code for this as well? I don't quite understand what you mean by standardize. C++ is C++ as far as I know, and only the complier you use would make any change to that.
Also, could you explain the difference between an iterator and a pointer in this case so I don't screw this kind of thing up again?
|
|
|
|
|
Christian Graus wrote: Assuming an iterator is a pointer, is allowed in VC6, but that is wrong. VC2002 was the first to fix this problem
I'm being a bit pedantic here, but it was always wrong to assume an iterator was a pointer. The fact that it worked on MSVC6 (or any past or future compiler) is just an impementation detail.
Steve
|
|
|
|
|
If an iterator is not a pointer, then what is it?
An instantiation of the template type stored as private member data in the vector class and set equivalent to any arbitrary instance stored in that vector?
|
|
|
|
|
An interator is a "pointer like" object. It can be a pointer or a class or struct . For example, how could a pointer possibly be used as an iterator for a linked list collection such as std::list or a binary tree such as std::set ?
Steve
|
|
|
|
|
I think I understand.
Did my supposed solution seem capable or am I still not understanding things clearly?
Might someone be able to give me an example of how I should write the assignment for magiitr?
Thank you.
|
|
|
|
|
I can't see any of the "<" or ">" characters on what's between in your code.
Steve
|
|
|
|
|
Kataric wrote: If an iterator is not a pointer, then what is it?
It is a generalization of a pointer that allows you to work with different data structures in a uniform manner.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I think the vector operator[] returns a reference to the element at that index, not an iterator.
So you'd want:
player::Magi& magi = Player1.Magi[mage1];
or
player::Magi* pMagi = &Player1.Magi[mage1];
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
I must seriously be confused here.
Like Mr. Echols is saying, I could declare a new instance of the player::Magi class and set Player1.Magi[mage1] equivalent.
However, I won't be able have any ->next functionality that comes with the vector iterator, and that's really what I'm after.
I'll also go back and look up references on the vector class.
I shall post more stuff in detail tomorrow in hopes that you can help me figure this out.
|
|
|
|
|
Hey Gentlemen, I contemplated opening a new thread for this question, but hopefully this one will do.
I think I understand what is going on with the darn pointers and interators and how I used them. Unfortunately I'll need to rewrite a lot of things.
However, I'm having another problem with another compiler error.
c:\nehe\magi\magination\spelllist.cpp(1275) : error C2228: left of '.current_energy' must have class/struct/union
The code is question is
caster.Creatures[i].current_energy = nrg[i];
I'm not sure what this "must have class/struct/union means.
Any help would be much appreciated.
|
|
|
|
|
This is typically the cause of that error (at least for me):
CMyObject* pObj = new CMyObject();
pObj.DoSomething();
Try changing it to:
caster.Creatures[i]->current_energy = nrg[i];
and see if that works.
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
Is there any fuction that compare 2 strs
str1 = "BMW"
str2 = "BmW"
and that fuction would return TRUE (or something else) while comparing these 2 strs?
or should i create that fuction ?
|
|
|
|
|
What are str1 and str2 ? char arrays ? std::strings ? CStrings ? bstr_t ?
Most string classes offer operator ==. Two char * can be compared with strcmp, from memory.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
|
I just want to return me true below :
CString str = "BMW";
CString str2 = "BmW";
CString str3 = "bMW";
if ( str == str2 && str2 ==str3) etc
|
|
|
|
|
use CompareNoCase function of CString..
|
|
|
|
|
Well i am facking idiot :/ it was inside my eyes and i did a whole post :/
|
|
|
|
|
hm i found MakeUpper for CStrings
so i will make them MakeUpper before i put them in if ( ) {}
right?
|
|
|
|
|
if (0 == str1.CompareNoCase(str2))
{
//strings are equal, ignoring case
}
"Posting a VB.NET question in the C++ forum will end in tears." Chris Maunder
|
|
|
|
|
thx about that too (i will use this and not that i said about MakeUpper)
|
|
|
|