I am having trouble simply using strcmp, I've never had this problem before. All I want to do is something like this...
What's wrong with that? It keeps complaining, saying:
char talk; // Also tried String *talk
if (strcmp(talk, "Hello"))
error C2664: 'strcpy' : cannot convert parameter 2 from 'System::String __gc *' to 'const char *'
It's like the two aren't at all compatible. I've done this many times before with no problems. By the way, this is a C++ Windows Forms Application in Visual Studio.NET if that matters.
Plese use code tags!
Didi you include <cstring> header?
Also your error is about strcpy, this is for string copying in C...
Please post the whole code!
You also seem to have some problem with how your compiler is set up. System::String is managed C++. Not ISO C++.
>> It's like the two aren't at all compatible. I've done this many times before with no problems. By the way, this is a C++ Windows Forms Application in Visual Studio.NET if that matters.
The actual name "Windows Forms Application" denotes managed C++. At least it does in 2003 (ISO C++ Forms apps are called something else).
strcmp() cannot be used with managed code, to my knowledge.
http://msdn2.microsoft.com/en-us/lib...em.string.aspx is the description of the system::string class. There you can find several compare and copy functions. This thread should probably be moved to the managed C++ forum
OK, let me explain better. Sorry, I'm just frustrated. I need to make a C++ app in Visual Studios that allows me drag-and-drop capability with objects like Textboxes, Buttons, etc. I have a 2 year programming degree but our teacher hated Windows so much that he would not teach us how to make a Windows app, only a console app, so I'm having to learn by myself.
The kind of app that I found in VS that has drag-and-drop is a Windows Forms Application (.NET)
Question 1: Is there a better one I should be using? (This is VS 2003 by the way.)
And I did #include <cstring> in stdafx.h. I've tried strings and char arrays. I will be manipulating pieces of text a lot in this program, so...
Question #2: Should I use char arrays or strings?
I thought the compiler might be complaining way too much because I'm making a Windows Forms Application, which I've never done before. (I'm used to only console apps.)
Question #3: Does this type of App make managed code automatically? If so, Is it a good idea to make it unmanaged? All of this stuff is new to me.
Q1: I don't know if Visual Studio 2003 offers RAD development for win32 apps developed on ISO C++. But Visual Studio 2005 does. Have you tried to start a win32 window project? Is there that option?
Q2: You should really use strings with C++ if you can. Character arrays should be considered only as a second option.
Q3: Highly debatable. If you are not after C++ in particular, but instead looking for a programming language to develop windows applications, I personally don't see a reason for you not to choose .Net. If, on the other hand, you prefer to cling to your knowledge of C++ then you must drop C++/CLI or C# and build unmanaged code in straight ISO C++
EDIT: Actually I went back to confirm over the web, and it seems VS2005 doesn't offer RAD for ISO C++ development. I'm honestly not sure on this bit. But at least, if VS2003 doesn't either, Borland offers it.
u can simply use CString instead of all that just:
this will return 0 if the 2 strings (s and "Hello") are identical, <0 if s is less than "hello", and >0 if s greater than "hello"
Whats the difference betwen string an CString?
CString is an MFC class. It makes sense to use it if you are using MFC, otherwise, you should use string, which is part of the standard library.