CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2010
    Posts
    2

    Need Help Regarding converting String to ASCII value

    hello everyone,

    Could you please help me out as how to convert string to ascii value.

    thanks,
    riya

  2. #2
    Join Date
    Jul 2009
    Location
    India
    Posts
    835

    Re: Need Help Regarding converting String to ASCII value

    A simple google search gives me the ans. See here

    And post post non-vc++ related query to this forum.

  3. #3
    Join Date
    Oct 2010
    Posts
    2

    Re: Need Help Regarding converting String to ASCII value

    @hypheni:thanks for the reply...i tried that but am getting error that says:-

    #error C2440: 'type cast' : cannot convert from 'class CString' to 'int'
    No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

    thanks,
    neha

  4. #4
    Join Date
    Sep 2010
    Posts
    66

    Re: Need Help Regarding converting String to ASCII value

    Code:
    #include <string>
    #include <iostream>
    
    using namespace std;
    
    int main () {
    	string s = "Hello";
    
    	cout << int(s[0]);
    
    		return 0;
    }
    Does that work for you?

  5. #5
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: Need Help Regarding converting String to ASCII value

    Quote Originally Posted by riya123 View Post
    @hypheni:thanks for the reply...i tried that but am getting error that says:-

    #error C2440: 'type cast' : cannot convert from 'class CString' to 'int'
    No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

    thanks,
    neha
    Can you post your code.
    You can cast characters to int, but not entire strings at once.
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured