|
-
January 29th, 2012, 05:40 PM
#1
New to C++, declaring a string issue
Hey hows it going guys. I am just learning c++ now because I have started a new job that works with computers so i figured itd be useful to learn. it is my first programming language and im excited.
Anyways, my issue is: I am trying to make my first form application, which includes just hardcoding my passwords for different usernames/accounts so when I enter a universal password, I can click the one I have forgotten, and it will display it.
I have created my forms but for some reason when I try to declare my string, I keep getting an error that says "There is no = binary operator that takes the right side of a string etc. blah blah"
My code right now is
string userpassword;
userpassword = txtPassword->Text;
Where userpassword is my string, and I want it to equal the text that is in my txtPassword (textbox).
What i did at first was something like,
if (userpassword = "beans") {open this new form blah blah}, but I got the same error message.
What is the proper way to write this piece of code? and can you explain to me why this is wrong?
Thank you very much. My dad helps me a lot with this but he only knows C# so he is confused by most of this stuff
-
January 29th, 2012, 06:00 PM
#2
Re: New to C++, declaring a string issue
 Originally Posted by Dan553
Hey hows it going guys. I am just learning c++ now
Anyways, my issue is: I am trying to make my first form application
Before doing anything else, know your tools.
That language that you use when you make forms applications is not C++ proper -- it is a Microsoft extension of C++ called Managed C++. It is not true ANSI C++. There is another forum here called Managed C++ that caters to that variety of C++.
The C++ that you see here in this forum is ANSI C++. This is the language described by Bjarne Stroustrup when he invented the C++ language. In addition this forum focuses on the Visual C++ compiler along with the libraries such as MFC and ATL. These libraries are written using ANSI C++.
Given the above, your code makes no sense in this forum. It is not valid C++. The way you create a string is either of the two:
Using CString:
Code:
CString s = _T("abc123");
CString s2 = s1;
if using standard string:
Code:
#include <string>
//...
std::string s = "abc123";
std::string s2 = s1;
So you have to decide is it Managed C++ (if so, you need to direct your question to the Managed C++ forum), or is it MFC or standard C++ (in that case this forum and the non-Visual C++ forum for the latter should be used).
Regards,
Paul McKenzie
-
January 30th, 2012, 02:52 PM
#3
Re: New to C++, declaring a string issue
 Originally Posted by Dan553
string userpassword;
userpassword = txtPassword->Text;
Hi,
Well this looks like C++ Managed, then you must declare a string variable as:
String^ userpassword;
userpassword = txtPassword->Text;
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|