CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: String compare error

  1. #1
    Join Date
    Dec 2017

    String compare error

    I'm retrieving the string from an edit control, the string is always 64 characters long, I need to check if the string is filled , when running the code I'm getting the error:

    error: request for member 'compare' in 'input', which is of non-class type 'char [64]'|


    	char input[64];
    	GetWindowText(to,input ,64);
    	if( input.compare("") ){
    		cout << 1 << endl;
    		cout << 0 << endl;
    Last edited by binary2; July 25th, 2018 at 09:49 AM.

  2. #2
    Join Date
    Aug 2006

    Re: String compare error

    You're using a C array of chars. C arrays don't have any members.

    Did you mean to use std::string? It has a compare member function.

    Anyway, you don't need to call compare for such a simple task. All you need to do is check the return value of GetWindowText.

    Last edited by TubularX; July 25th, 2018 at 06:14 PM.

  3. #3
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Hanover Germany

    Re: String compare error

    Quote Originally Posted by binary2 View Post
    I'm retrieving the string from an edit control, the string is always 64 characters long, I need to check if the string is filled...
    You may want to use GetWindowTextLength function to retrieve the text length.
    Victor Nijegorodov

  4. #4
    Join Date
    Dec 2017

    Re: String compare error

    Thank you!

  5. #5
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012

    Re: String compare error

    the string is always 64 characters long
    Passing 64 to GetWindowText() says that the maximum returned string length is 63 (plus 1 for the null terminator). The actual length of the returned string can be any value from 0 to 63. The returned value from this function gives the actual string length.

    const size_t MaxSize = 64;
    char input[MaxSize];
    auto txtlen = GetWindowText(to, input, MaxSize);
    if (txtlen == 0)
        cout << "No window text!" << endl;
        cout << input << endl;
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2017 (15.7.6)

Posting Permissions

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

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)