DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: no conversion from 'int' to 'System::String ^'

  1. #1
    Join Date
    Apr 2011
    Posts
    20

    no conversion from 'int' to 'System::String ^'

    Hi guys,

    I am having a trouble with the boolean. I am trying to get access to my website script and see if it have response through the httpwebrequest method, then check if the bool is valid then login to the system to receive the information.


    Code:
    private: System::Void Button1_Click(System::Object^ sender, System::EventArgs^ e) {
    
           try
          {
            //Address of URL
            String ^URL = "http://www.mysite.com/myscript.php?user=" + TextBox1->Text + "&pass=" + TextBox2->Text;
            HttpWebRequest ^request = safe_cast<HttpWebRequest^>(WebRequest::Create(URL));
            HttpWebResponse ^response = safe_cast<HttpWebResponse^>(request->GetResponse());
            StreamReader ^reader = gcnew StreamReader(response->GetResponseStream());
            String ^str = reader->ReadToEnd();
            <br/>
            if (request->HaveResponse)
            {
              MessageBox::Show("connected ok, now let login!");
              try
              {
                //Address of URL
                String ^URL1 = "http://www.mysite.com/myscript.php?user=" + TextBox1->Text + "&pass=" + TextBox2->Text;
                HttpWebRequest ^request1 = safe_cast<HttpWebRequest^>(WebRequest::Create(URL1));
                HttpWebResponse ^response1 = safe_cast<HttpWebResponse^>(request1->GetResponse());
                StreamReader ^reader1 = gcnew StreamReader(response1->GetResponseStream());
                String ^str1 = reader1->ReadToEnd();
                
    
                //Do login stuff here.
                bool login = false;
                //User Login
                login = true;
    
                if (str == login)
                {
                  MessageBox::Show("You are now login!");
                  //Check if two users are login at the same time.
                  bool checklogin = false;
                }
            }
          }
    }


    The arguments are jumping on the statement of if (str == login). I have got two errors which it is:

    Error: error C2446: '==' : no conversion from 'int' to 'System::String ^'

    Error: error C2040: '==' : 'System::String ^' differs in levels of indirection from 'int'



    I have used the statement as if (str ==login.ToString()), but I did not get the return argument. I have tried to use each different properties, but there are still variable and I still has no return argument. What I am trying to do is to get access to the website, check if the login details is valid then display the messagebox that says "You are now login!".



    Any advice would be much appreciate.

    Thanks!

  2. #2
    Join Date
    Jan 2005
    Location
    UK
    Posts
    604
    Code:
    if (str == login)
    you are comparing a string with a bool - that's not possible
    DKyb
    -------------------------------
    Life is a short warm moment -
    Death is the long cold rest.
    Pink Floyd
    -------------------------------

  3. #3
    Join Date
    Apr 2011
    Posts
    20
    thanks for your quick replied. do you know how to do a comparing a string with a bool?

  4. #4
    Join Date
    Jan 2005
    Location
    UK
    Posts
    604
    You can't. Period. You can write your own comparison operator
    Code:
    bool operator == (const std::string& s, bool b)
    {
         return (s=="true" && b==true) || (s=="false" && b==false);
    }
    or some nonsense like that, but you're better off to create a
    Code:
    bool toBool(const str& str)
    {
         // make s lowercase
         string s=myMakeLower(str);
         return s == "1" || s == "t" || s == "true" || s == "y" || s == "yes";
    }
    and then compare the result of that with the bool.
    But it does not make sense to compare a string with a bool really...
    Last edited by drkybelk; 05-27-2011 at 01:23 PM.
    DKyb
    -------------------------------
    Life is a short warm moment -
    Death is the long cold rest.
    Pink Floyd
    -------------------------------

Similar Threads

  1. Replies: 0
    Last Post: 03-18-2007, 02:25 PM
  2. No
    By chintucs in forum Java
    Replies: 2
    Last Post: 01-21-2007, 05:08 PM
  3. Typedef Declaration in VB
    By floydus in forum VB Classic
    Replies: 7
    Last Post: 06-05-2006, 05:49 PM
  4. KeyListener not responding
    By lordanki in forum Java
    Replies: 3
    Last Post: 04-04-2006, 10:13 AM
  5. INSERT for multiple tables with IDENTITY
    By Kay in forum Database
    Replies: 1
    Last Post: 07-04-2001, 05:18 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center