Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help, i'm switched from Borland C++ builder to VC++ 1

Status
Not open for further replies.

GeertJ

Programmer
Aug 4, 2004
3
BE
Hi all,

I hope this is the right forum i post my message, else, beat me :)
Recently, i swichted from Borland C++ builder (BCB) to Visual studio.net because it has some advantage that C++ builder does'nt have. Because I'm used to program in BCB, now I can't program simple things in VC++. Things like get a string out a textBox and convert it to i.e. a Integer. I searched today the internet and found a possible way to do that, with the command "atoi".
this is what i've got.

int number = atoi(textBox1->Text);

but when i build that, i've got errors like, cant convert this to that...
Can somebody help me with this?

thanxs in advance

Geert J
 
atoi() is part of the stdlib.h and not VC++ specific feature. Its declaration (as defined by ANSI C++) is as follow:

int atoi (const char* s);

The problem you are having may have something to do with converting textBox1->Text into const char* type. You need to know what type textBox1->Text is and use appropriate explicit cast to solve the problem.

The following code snipet assumes that textBox1->Text is of type CString.

Code:
int number = atoi((LPCTSTR)textBox1->Text);

In this case, LPCTSTR converts CString object into a read-only C-style null terminated string.

I hope this helps.

Zech
 
Hi,

I tried that, but stil i've got a lot of errors.
My code used:
Code:
private: System::Void button1_Click(System::Object *  sender, System::EventArgs *  e)
			 {
				 int number = atoi((LPCTSTR)textBox1->Text);
			 }
what i get when compile:
Code:
Compiling...
stdafx.cpp
Compiling...
AssemblyInfo.cpp
Form1.cpp
c:\Documents and Settings\Geert\Mijn documenten\Visual Studio Projects\Testproject3\Form1.h(87) : error C2065: 'LPCTSTR' : undeclared identifier
c:\Documents and Settings\Geert\Mijn documenten\Visual Studio Projects\Testproject3\Form1.h(87) : error C2146: syntax error : missing ')' before identifier 'textBox1'
c:\Documents and Settings\Geert\Mijn documenten\Visual Studio Projects\Testproject3\Form1.h(87) : error C2059: syntax error : ')'
C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\WinNT.h(323) : error C2378: 'LPCTSTR' : redefinition; symbol cannot be overloaded with a typedef
Generating Code...

It's probably something really stupid, but i can't find it.
other suggestions??
anyway, thanks for the reaction Zech,

Geert
 
Hmm...

What kind of error you get when you try

int number = atoi(textBox1->Text);
 
this:
Code:
error C2664: 'atoi' : cannot convert parameter 1 from 'System::String __gc *' to 'const char *'
        Cannot convert a managed type to an unmanaged type
could it been that there is something wrong configurated?
 
Apparently, you are using the managed C++ project.

I am not that familiar with Managed C++. In fact, I am still trying to learn it and often wonder whether the features introduced by Managed C++ really are necessary.

Managed C++ is Microsoft's extension of C++. It is somewhat different from the standard C++, and it has some additional stuffs that you need to learn. Managed C++ introduces features that supposedly help the programmers from 'digging their own graves' when coding. Despite some people finding the features helpful, I personally find those features to be somewhat limiting and restrictive (I am not sure where Microsoft is going with C++, Managed C++, and C# ... geez).

I am pretty sure that there are people more familiar with Managed C++ than I do in this forum who can help you out with this problem. Alternatively, you can use the unmanaged C++ (just dont pick the managed c++ when starting the project), which is closer to the standard C++. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top