problem with microsoft C compiler doesn`t accept things gcc does,how to solve? (encoding)


Here is the example code.

int main(int argc, char *argv[])
{
string Result;
WIN32_FIND_DATA daten;
HANDLE h = FindFirstFile(TEXT("c://test"), &daten);
system("PAUSE");
return EXIT_SUCCESS;
}

It works fine with DevCpp and gcc.

The error with microsoft C compiler is that he can`t convert from string
to LPCSTR.

I think the problem is inside the encoding, ansi, unicode, ... Found
some ways to avoid this error but all are not very awesome.

Please tell me the best way to solve this.
Posted On: Monday 5th of November 2012 12:48:21 AM Total Views:  440
View Complete with Replies

RELATED TOPICS OF C Language PROGRAMMING LANGUAGE




debugging problem

I'm developing software for Linux on my desktop. The software gets compiled and the binary is downloaded to the target system where i can't install a debugging system or something. I've written following code: #ifdef INIT_REPORT std:fstream out("/usr/share/NovaxTSP/INITreport.txt", std::ios_base::in | std::ios_base:ut | std::ios_base::app); if(!out) { // if out couldn't be opened, print error and exit std::cout
VIEWS ON THIS POST

334

Posted on:

Sunday 4th November 2012
View Replies!

pointerproblem with derived class

, I have a number of classes, base classes an derived which use pointers to objects of each other. Now there are problems with the types. I best explain with an example. I name one line of classes A and one B: class Tbase_A { // some properties and methods } class Tbase_B { Tbase_A ** List_ptr_base_A // more properties // methods do some work on a list of pointers of Tbase_A like storing data of all those base_A objects to a file void __fastcall do_something (void); } class Tderived_A : public Tbase_A { more properties and methods } My current project only works with Tderived_A. I have a list of pointers to a number of objects of type Tderived_A on which I wish to use the methods of Tbase_B: Now I tried two possibilities: Tderived_A ** List_ptr_derived_A [] = { &obj1_derived_A, &obj2_derived_A, &obj3_derived_A, &obj4_derived_A, //.... } And then in the program: obj_base_B.List_ptr_base_A = List_ptr_derived_A; This fails at compilation, because the types are not equal. If I change the type of the list: Tbase_A ** List_ptr_derived_A [] = { &obj1_derived_A, &obj2_derived_A, &obj3_derived_A, &obj4_derived_A, //.... } And then in the program: obj_base_B.List_ptr_base_A = List_ptr_derived_A; This is ok at compile time. But this: obj_base_B.do_something (); fails at runtime, execution ends in a mess of misinterpreting data of the objects. As much as I have seen this comes from interpreting the data structure of an object of type Tderived_A as if it was Tbase_A. So it seems there is an implicit type cast done, when I set addresses of objects of T_derived_A in a list of type addresses of Tbase_A. I understand that both cannot work. But where is a way to get the functions that are there in Tbase_B to work on objects of Tbase_A also to work on objects of Tderived_A. I hope I could clearly describe my problem. Thank you for any help. Martin
VIEWS ON THIS POST

153

Posted on:

Sunday 4th November 2012
View Replies!

problems with inheritance and protected attributes

all, I'm working on a project with a layout similar to this: class A { protected: A *next; int i; public: void m(A *a); }; class B: public A { public: void m(B *b); } where both A and B are linked lists, but each one of its own type, and m is a method that manipulates A's 'next' attribute, for instance: A::m(A *a) { a->next = next; i++; } as the behavior would be exactly the same for B, I did: B::m(B *b) { A::m(b); } But that gives me errors on compiling whenever method B::m, tries to access a protected member of class A (for instance incrementing i). I've tried declaring a new variable i to class B, but that just causes both A::i and B::i to exist, and A increments A::i, while whenever someone reads from B, it reads B::i. Which is obviously wrong. Does anybody know how I can fix this Did anybody even understand what I just asked I know I kinda lost me. :P Any help would be greatly appreciated, Lucas , * Lucas Kanebley Tavares: > On Sep 30, 3:23 am, "Alf P. Steinbach" wrote: >> It would be nice if you posted the actual offending code, but happily >> this "problem" is not uncommon, so it is reasonable to assume you have >> something like >> >> B::m( B* b ) >> { >> A::m( b ); >> next->i = 666; >> } >> >> That will cause the compiler to complain, because while B can access >> protected A features on B objects, and on objects of classes publicly >> derived from B, if it could do it could access protected A features on A >> objects it could also access protected A features on Z-objects, where Z >> is a class I have derived from A. >> >> So in that case "protected" wouldn't be any protection: you could access >> protected A features of my Z instances simply by deriving a class from A. >> >> So C++ does not allow that. > > --- Compiler error > wwperiod.hpp: In member function 'virtual double > ZWPeriod::getMinimalCost()': > wwperiod.hpp:50: error: 'DATATABLE* WWPeriod::resTable' is protected > zwperiod.cpp:46: error: within this context > (and the same error for a lot of other attributes in the same > method). > > --- Classes layout > class WWPeriod { > public: > virtual double getMinimalCost(); > protected: > DATATABLE *resTable; > > }; > > class ZWPeriod: public WWPeriod { > public: > virtual double getMinimalCost(); > > }; > > --- Line giving the presented error: > zwperiod.cpp:46: resTable[0].tempCost = prev->resTable[0].tempCost + > prev->holdCost; > > --- > > I'm a reasonably good C programmer, but although I know C++ syntax, > I've never really had any serious projects in C++, so I'm > unexperienced. > > Thank you for your reply, but my problem remains. > Any more suggestions for a n00b Only to reconsider the above earlier suggestion, which is now confirmed. The (or at least one) problem is the attempted access via prev->, as I surmised it would be. Why that is not permitted is explained above. How to possibly fix it, explained above -- and perhaps also take a look at the suggested redesign. In addition to the earlier advice, with concrete code I can now make the suggestion to introduce public inline const accessors tempCost() and holdCost() in the base class, and change the naming convention for data members to e.g. myTempCost or tempCost_. By the way, please don't top-post (rearranged, see the FAQ please), and please don't quote signatures. Cheers, & hth., - Alf -- A: Because it messes up the order in which people normally read text. Q: Why is it such a bad thing A: Top-posting. Q: What is the most annoying thing on usenet and in e-mail
VIEWS ON THIS POST

306

Posted on:

Sunday 4th November 2012
View Replies!

Thanks, the problem has been solved.


VIEWS ON THIS POST

135

Posted on:

Sunday 4th November 2012
View Replies!

please help - file input problems

I'm reading in a datafile that is primarily stored as 1-byte ints. I've tried using cin, fread, fgetc, and fscanf - but all these methods ignore a value of 13 and skip it entirely, returning the next value instead. What method can i use that will not strip data out as whitespace
VIEWS ON THIS POST

230

Posted on:

Sunday 4th November 2012
View Replies!

Navigation and understanding problems with C++ code, Please help

Experts & Beginners, I'm definitely not an expert, but believe that can become one day....and the journey has already started....and here is a possible milestone, if you can help. I work for a company that has a very nice embedded product, and I have been involved in system design and testing for this product. Now, I am trying to get some understanding of software, which is a model-based C+ + software. It is developed using Rhapsody. My question is: I am not able to follow the huge code with several packages and libraries with accurate understanding since I have not written it. I am confused by the syntax and naming rules. I tried to find some details on how people (programmers) name structures, classes (special type of classes), objects, constructors, destructors, functions,..etc., and how to navigate between different parts of the code to follow the implemented logic...but has no luck so far. Can anyone help me how I should dive into this How you did when you were a beginner and had faced similar situation I believe, all I need is some guidance that can save me wondering around the code files. replies are greatly appreciated.
VIEWS ON THIS POST

223

Posted on:

Sunday 4th November 2012
View Replies!

String::Format problem (VC++ .NET 2003)

I spent many hours on this, googling around and experimenting, and still nothing. I wrote an umanaged program (actually various classes), while I was developing them I used command line to test it. Now, I decided to make GUI for it, so I created new project: "Windows Forms Application (.NET)" (I was trying to use something that's not managed (e.g. MFC, but I learned quickly that I don't actually know how to use MFC In .NET I was able to quickly create the GUI that looked as I wanted it too look. Now my problem is really silly. While I figured out how to convert System::String to for example std::string, and looks like the other way around is actually easy, I can't for a love of God make String::Format do what I want. Even the examples from MSDN doesn't work when I copy&paste them verbatim! Here is an example: http://msdn2.microsoft.com/en-us/library/fht0f5be.aspx In a simple program that has just textbox, button and label, the following code works: label1->Text = String::Format(", {0}", textBox1->Text); But this, doesn't want to: label1->Text = String::Format(", {0}", 10); My goal is basically do something like this: unsigned short int pc = 8000; label1->Text = String::Format("Address: {0,4:X}", pc); Anyone has idea what I'm doing wrong I have also an unrelated question: If I have a managed class (for the form), and I define inside a pointer to an unmanaged class, is that a good practice Right now it appears to work fine, but before I had an exception that the pointer is null (even though I did new on the form's load, and pointer was used after selecting an option from a menu). I have no idea how I even fixed it.
VIEWS ON THIS POST

141

Posted on:

Sunday 4th November 2012
View Replies!

A weird problem on structure and union alignment

Please forgive me for cross-posting. I've post this to microsoft.publoc.vc.mfc. But I can't get any response. Maybe only MFC- related topics are cared there. To begin with code: union XXX { double a; char b; double c; }; XXX s; size_t n1 = sizeof(XXX); size_t n2 = __alignof(double); size_t n3 = __alignof(XXX); double* p1 = &s.a; char* p2 = &s.b; double* p3 = &s.c; XXX* p4 = &s; Compiler: VS 2005 + SP1 Output: n1 = 8 n2 = 8 // the largest member in the union is 8-byte aligned! n3 = 4 // \t, it should be 4 less than 8 p1 = 0x0012F5B4 // \t, it is not 8-byte aligned! p2 = 0x0012F5B4 // ditto p3 = 0x0012F5B4 // ditto p4 = 0x0012F5B4 // ditto Below is a related article copied from the site "The Old New Thing". Because posting new comments to the original post has been disabled, so I have to put it here. Please note the first comments to the post by Roger Lipscombe, He/She says: "the C standard states that they must be aligned suitably for the largest contained member." However, I can't find any statement in the C standard, Is that implementation- defined
VIEWS ON THIS POST

206

Posted on:

Sunday 4th November 2012
View Replies!

Class reference member problem

i have the following situation class B { static B createBobj(); } Class A { func() { m_obj = createobj(); } B& m_obj; }; Obviously doesn't compile so In class A i want to hold a reference to an instance of class B created by the factory method createBObj. i can't initialise my reference member in constructor as class A needs to do some other initialisation before creating instance of B. So how to solve this problem
VIEWS ON THIS POST

184

Posted on:

Sunday 4th November 2012
View Replies!

iterator problem

I built a container (without a template), an iterator as a nested class and a "find"-method: iterator has a friend relationship with Hash_Map and vice versa. class Hash_Map { iterator find ( value_type ) // Line 6 { search something..... return iterator( Param ); } class iterator : public std:iterator // Line 16 { iterator( param_type Param ){ do something } // constructor various operators and so on..... }; } I get the following error message from VS2005: "Line 6: std::iterator use of class template requires template argument list" If i write Line 6 as iterator find ( value_type ) everything compiles fine. Why do i have to repeat the template instantiation if i already have done this on line 16 via the inheritance books i read about the STL don't need the template instatiation on Line 6. Did i domething wrong Greetings A.Gallus
VIEWS ON THIS POST

244

Posted on:

Sunday 4th November 2012
View Replies!

namespace & typedef problem

World!!! I have the following code First File (.hpp) //---------------- namespace A { typedef unsigned short ushort class myClass //definition } Second File (.cpp) //--------------- namespace A { class myClass //implementation } Third File (.cpp) //--------------- namespace A { string itos(ushort i) { //some code } } the problem is that in the third file the ushort isn't recognized why\t
VIEWS ON THIS POST

153

Posted on:

Sunday 4th November 2012
View Replies!

the diamond problem

I was trying to avoid virtual inheritance recently (performance) A / \ B C \ / D and I wondered if it would be possible for a compiler to arrange the fields like this class A { stuff } class B : virtual public A { B subobject A subobject } class C : virtual public A { A subobject C subobject } class D : public B, public C { B subobject A subobject C subobject } and so negate the need for virtual inheritance pointers. would that work i realise for more than 2 base classes you'd need objects with holes in. a compiler that did this would be pretty neat, IMO -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
VIEWS ON THIS POST

143

Posted on:

Sunday 4th November 2012
View Replies!

library problem

I have a little problem. Read this please: //library.h class myClass { public: myClass(); static myClass *instance(); private: static myClass *self; }; //library.cpp #include "library.h" myClass::myClass() { self = this; //more initialisation stuff } myClass *myClass::instance() { return self; } i compiled this 'library': g++ -Wall -fPIC -c library.cpp -o library.o g++ -Wall -shared -o libLibrary.so library.o without any errors then: i tried to use my 'library': // main.cpp #include "library.h" int main() { myClass test; // do something usefull with the test class return 0; } that's it! but it won't compile! it gave the error: g++ -lLibrary main.cpp -o test libLibrary.so: undefined reference to myClass::self collect2: ld returned 1 exit status can anyone tell me what i am doing wrong this isn't the real library, that one is much bigger, but this is the part what is producing the error.
VIEWS ON THIS POST

149

Posted on:

Sunday 4th November 2012
View Replies!

what is the problem with static main()

What is the precise problem for which we cant declare main() as static. I know there is no reason to do so but still I wish to know the precise technical problem for which it is disallowed.
VIEWS ON THIS POST

144

Posted on:

Monday 5th November 2012
View Replies!

cin stream problem.

everybody. I am trying to protect a customer to enter char instead of number and i have created the program as below: int main() { int number; do { cin.clear(ios::failbit||ios::eofbit); cout > number; } while(cin.fail()); cout
VIEWS ON THIS POST

154

Posted on:

Monday 5th November 2012
View Replies!

Re: int to char problem ?

> > b'coz ex. 56+ > 5 => 53 > 6 => 54 > sum is 107 => k but i want 11 not k and push in vector is 11 plese > help. Note one fact that: '0' -> 48 .... '5' -> 53 '6' -> 54 therefore: '6' - '0' -> 6 '5' - '0' -> 5 You need to write "temp = (_stack.getpop() - '0') + (_stack.getpop() - '0'); ".
VIEWS ON THIS POST

233

Posted on:

Monday 5th November 2012
View Replies!

new problem?

buffer = new char[4535+308]; The above appears to only allocate 4535 bytes. The debugger and codeguard both show this as only 4535 bytes. No tricks, just the above seems to do it. bcb studio 2006. Does anyone else get these results
VIEWS ON THIS POST

152

Posted on:

Monday 5th November 2012
View Replies!

Migration BCB6 to BDS2006, problems with vectors

I've problems when migrate from BCB6 to BDS2006. In BCB6 iterators of vectors can handled over to functions and can be converted to different types as shown below. With BDS2006 it semms to be impossible or more restricted. Is there any solution for this problem class PACKAGE TObcStation : public TCsStation { public: __fastcall TObcStation(const UCHAR StationNr, TCsProcessor* Processor); ..... } //--------------------------------------------------------------------------- void __fastcall TCsSystem::SearchSomeWhat() { vector ::iterator obc_iter; for(obc_iter = ObcProcessors.begin(); obc_iter < ObcProcessors.end(); obc_iter++) { TObcStation Obc9600Station(ucStation, obc_iter); //here I get Error E2285 like: "no match found of..." } ..... //--------------------------------------------------------------------------- void __fastcall TCsSystem::SearchSomeWhat() { vector ::iterator obc_iter; for(obc_iter = ObcProcessors.begin(); obc_iter < ObcProcessors.end(); obc_iter++) { TObcStation Obc9600Station(ucStation, (TCsProcessor*)obc_iter); //here I get Error E2031, like: "type casting forbidden" } Roland
VIEWS ON THIS POST

183

Posted on:

Monday 5th November 2012
View Replies!

Rat in a maze problem

Rat in a Maze pblm can be solved using Stack data structure but shortest possible path can't be found using it(but we can found a possible path).To find shortest possible path without calculating length of path which data struc. should be used .plz also describe algo to solve it. we can find all possible path using Stack..... then calculate length of each possible path and find shortest one but its very time and space consuming soln.
VIEWS ON THIS POST

142

Posted on:

Monday 5th November 2012
View Replies!

static data members in template class problem

Following code gives a linker error: test.obj : error LNK2001: unresolved external symbol "public: static int const BresenhamCircle::SIZE" template class BresenhamCircle { public: static const int SIZE; }; template class Test { BresenhamCircle circle; public: int testfunction();//[1] { return circle.SIZE+1000*R; } }; template int Test::testfunction() { return circle.SIZE+1000*R; } template const int BresenhamCircle::SIZE = -1; const int BresenhamCircle::SIZE = 4; #include int main() { Test obj; //[2] Test obj; std::cout
VIEWS ON THIS POST

159

Posted on:

Monday 5th November 2012
View Replies!