Counting letters in a string

Pages: 12
I just have a couple more errors to get rid of so far:

1>NTS.cpp(132): error C2065: 'cli_msg' : undeclared identifier
1>NTS.cpp(133): error C2660: 'System::IntPtr::ToPointer' : function does not take 1 arguments

I have looked all over the place for the right namespace or #include that will support those identifiers.
Please post your entire code here.
#1 cli_msg is just the name I chose for my variable. Use whatever name you used for your variable. (In my easrlier post, I assumed my code fragments ran on from each other).

String^ my_str = gcnew String(etc); // etc already declared

#2 IntPtr::ToPointer doesn't take one argument. It's called againt a variable without an arguent.

Andy

PS MSDN is the place you need to for .Net info -- http://msdn.microsoft.com -- rather than cplusplus.com's reference -- which is for (native) C++
Last edited on
Alright, the program compiles correctly so far with converting the String to the char. Here is what I put together so far, just to make sure that everything is in its right place:

1
2
3
4
5
6
            String^ cli_str = gcnew String(cli_str);
	    char buffer[1024]; // need to be careful with buffer size in real code
	    IntPtr hglob = Marshal::StringToHGlobalAnsi(cli_str);
	    char* str = static_cast<char*>(hglob.ToPointer());
	    strcpy_s(buffer, str);
	    Marshal::FreeHGlobal(hglob);
Your first line is going to cause confusion. You're feeding the new variable back into its own constructor...
What is etc then and what type is it?
"etc" is whatever char* variable you need to convert to a System::String

Looking back at the thread, this should have been obvious from earlier examples (see e.g. my post of Nov 21, 2012 at 3:03am)
Last edited on
Alright, that issue is done with. Now, I got the textBox linking issue with:
String^ input = this->textBox1->Text = cli_str;


The following compiler errors have occurred:

1>NTS.cpp(106): error C2065: 'str' : undeclared identifier
1>NTS.cpp(113): error C2355: 'this' : can only be referenced inside non-static member functions
1>NTS.cpp(113): error C2227: left of '->textBox1' must point to class/struct/union/generic type
1>NTS.cpp(113): error C2227: left of '->Text' must point to class/struct/union/generic type
Those are compiler errors. To fix them you just need to use the right variable name. And call the functions inside a membe function of the form.

All these error are minor, generic C++ errors. See the cplusplus.com tutorials for information about varaibles and classes (inc. static vs other members)
Topic archived. No new replies allowed.
Pages: 12