Thread: If statement

  1. #1
    Registered User
    Join Date
    Apr 2013
    Posts
    34

    If statement

    I think it's not working, but is it possible to do something like that to avoid that hard typing?
    Code:
    char c;
    if(  c == ('ą' || 'č'||'Ą'||'Č'||'ę'||'Ę'||'ė'||'Ė'||'į'||'Į'||'š'||'Š'||'ų'||'Ų'||'ū'||'Ū'||'ž'||'Ž') )
    {
           //do stuff
    }

  2. #2
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Try this:
    Code:
    char c ; 
    ...
    std::string s = "ąčĄ"; //etc
    ...
    if (s.find(c) != std::string::npos)
    {
        ...
    }

  3. #3
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158
    Quote Originally Posted by Aeoskype View Post
    Code:
    if(  c == ('ą' || 'č'||'Ą'||'Č'||'ę'||'Ę'||'ė'||'Ė'||'į'||'Į'||'š'||'Š'||'ų'||'Ų'||'ū'||'Ū'||'ž'||'Ž') )
    This does not work, because the code to the right of the == is run first. C++ doesn't have a "shorthand" for comparing. To do what you want in the same fasion you'd have to do
    Code:
    if(c == 'ą' || c == 'č' || c == 'Ą' || etc...
    manasij7479's solution is the correct way.

  4. #4
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158
    Quote Originally Posted by Aeoskype View Post
    Code:
    if(  c == ('ą' || 'č'||'Ą'||'Č'||'ę'||'Ę'||'ė'||'Ė'||'į'||'Į'||'š'||'Š'||'ų'||'Ų'||'ū'||'Ū'||'ž'||'Ž') )
    This does not work, because the code to the right of the == is run first. C++ doesn't have a "shorthand" for comparing. To do what you want in the same fasion you'd have to do
    Code:
    if(c == 'ą' || c == 'č' || c == 'Ą' || etc...
    manasij7479's solution is the correct way.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. If Statement - The best way
    By jromeo7777 in forum C Programming
    Replies: 4
    Last Post: 09-27-2013, 09:42 AM
  2. EOF Statement in C++
    By Vespasian in forum C++ Programming
    Replies: 5
    Last Post: 09-24-2013, 02:14 PM
  3. Statement inside a statement.
    By JOZZY& Wakko in forum C Programming
    Replies: 15
    Last Post: 11-05-2009, 03:18 PM
  4. if statement
    By junkeat90 in forum C++ Programming
    Replies: 5
    Last Post: 01-10-2008, 12:35 PM
  5. if statement
    By Joe100 in forum Game Programming
    Replies: 1
    Last Post: 12-07-2003, 05:57 AM