my if statements

This is a discussion on my if statements within the C++ Programming forums, part of the General Programming Boards category; i cant find my problem, it says "missing ) before string" but i think i have all my ')' 's ...

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    266

    my if statements

    i cant find my problem, it says "missing ) before string"
    but i think i have all my ')' 's

    Code:
    	if((convert == "edit") || (convert == "Edit") || (convert == "EDIT"))
    	{
    	edit_file.open(tfilename.c_str(), ios::app);
    	cho = 1;
    goto theend;
    	}
    	else if((convert == "new") || (convert == "New") || (convert == "NEW"))
    	{
    	new_file.open(tfilename.c_str());
    	cho = 2;
    goto theend;
    	}
    	else if((convert == "read") || (convert == "Read") || (convert "READ"))
    	{
    	read_file.open(tfilename.c_str(), ios::in);
    	cho = 3;
    goto theend;
    	}
    	else if((convert == "exit") || (convert =="Exit") || (convert == "EXIT"))
    	{
    		cho = 4;
    goto theend;
    	}
    o yea, on a side note,,,would this work , right after this
    Code:
    		cho = (int)convert.c_str()[0];
    Last edited by rodrigorules; 11-29-2005 at 11:35 AM.

  2. #2
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    should be
    Code:
    else if((convert == "read") || (convert == "Read") || (convert == "READ"))
    Kurt
    Last edited by ZuK; 11-29-2005 at 11:49 AM.

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,325
    >> would this work

    That would assign the character set value for the first character in the convert string to cho. If convert is "new" and you're using ASCII, then cho would be 110. If convert was "read" it would be 114. If convert was empty and you left the c_str() there, cho would be 0 (if convert is not empty you don't need the c_str(), since you can use [] on a string just like a character array). If that's what you want, then it would "work".

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Unknown memory leak with linked lists...
    By RaDeuX in forum C Programming
    Replies: 6
    Last Post: 12-07-2008, 03:09 AM
  2. newbie question - if statements without conditions
    By c_h in forum C++ Programming
    Replies: 2
    Last Post: 07-18-2008, 10:42 AM
  3. C++ If Statements Help
    By moporho in forum C++ Programming
    Replies: 19
    Last Post: 01-18-2008, 07:40 AM
  4. Efficiency of case statements
    By Yasir_Malik in forum C Programming
    Replies: 26
    Last Post: 05-23-2006, 11:36 AM
  5. Need help with "if" statements
    By Harryt123 in forum C Programming
    Replies: 22
    Last Post: 05-14-2006, 08:18 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21