Hello and welcome to our community! Is this your first visit?
Register
Results 1 to 4 of 4
  1. #1
    Regular Member
    Join Date
    Jul 2008
    Location
    Why are you reading this pedofile?
    Posts
    248

    C++ Syntax Error

    Okay, I stopped learning C++ because reading tutorials is boring. I got rusty. I found video tutorials and enjoy C++ again. But, for some reason I can't get this code to work.

    Code:
    #include <iostream>
    
    char cName[];
    char YesNo;
    
    using namespace std;
    
    int main() {
       
       do {
          cout << "Please enter your name: ";
          cin >> cName;
          cout << "Your name is: " << cName << ", is that correct? (y/n)" << endl;
          cin >> YesNo;
             if (YesNo == 'y') {
                cout << "Thank you." << endl;
             } else {
                cout << "Please re-enter your name: " << endl;
             }
             while (YesNo != 'y');
       }
    
    }
    I use Visual C++ Express 2008, and the video tutorials from XoaX teaches code used in most compilers. So why doesn't this work ? The error I received was:
    (23) : error C2059: syntax error : '}'
    (23)=line 23

  2. #2
    Regular Member
    Join Date
    Jul 2008
    Location
    Why are you reading this pedofile?
    Posts
    248

    Re: C++ Syntax Error

    I guess you forgot you cant use '==' to compare strings. I use Visual C++ 2008 Express and when I compiled your code I got these errors:

    (19) : error C2678: binary '==' : no operator found which takes a left-hand operand of type 'std::string' (or there is no acceptable conversion)

    (19) : error C2678: binary '==' : no operator found which takes a left-hand operand of type 'std::string' (or there is no acceptable conversion)
    could be 'built-in C++ operator==(const char [2], const char [2])'
    while trying to match the argument list '(std::string, const char [2])'


    edit: I edited my first post with the error I got from the first code I posted

  3. #3
    Obsessed Veteran Adam's Avatar



    Join Date
    Nov 2004
    Location
    UK / England
    Posts
    17,271

    Re: C++ Syntax Error

    Strcmp should be used for string comparision ideally.

    You're not comparing string though, your comparing characters. CodeMachine just doesn't know how to use his quotes correctly. In your instance you require single quotes.

  4. #4
    Regular Member
    Join Date
    Jul 2008
    Location
    Why are you reading this pedofile?
    Posts
    248

    Re: C++ Syntax Error

    I tried with single quotes again, and these errors arose:


    while trying to match the argument list '(std::istream, std::string)'
    c:\documents and settings\biggestcncfanever\desktop\whatever 2\coding and programming\c+ c++ c#\console practice 1\console practice 1\main.cpp(19) : error C2784: 'bool std:perator ==(const std::istreambuf_iterator<_Elem,_Traits> &,const std::istreambuf_iterator<_Elem,_Traits> &)' : could not deduce template argument for 'const std::istreambuf_iterator<_Elem,_Traits> &' from 'std::string'
    c:\program files\microsoft visual studio 9.0\vc\include\streambuf(548) : see declaration of 'std:perator =='
    c:\documents and settings\biggestcncfanever\desktop\whatever 2\coding and programming\c+ c++ c#\console practice 1\console practice 1\main.cpp(19) : error C2784: 'bool std:perator ==(const std::istreambuf_iterator<_Elem,_Traits> &,const std::istreambuf_iterator<_Elem,_Traits> &)' : could not deduce template argument for 'const std::istreambuf_iterator<_Elem,_Traits> &' from 'std::string'
    c:\program files\microsoft visual studio 9.0\vc\include\streambuf(548) : see declaration of 'std:perator =='
    c:\documents and settings\biggestcncfanever\desktop\whatever 2\coding and programming\c+ c++ c#\console practice 1\console practice 1\main.cpp(19) : error C2784: 'bool std:perator ==(const std::istreambuf_iterator<_Elem,_Traits> &,const std::istreambuf_iterator<_Elem,_Traits> &)' : could not deduce template argument for 'const std::istreambuf_iterator<_Elem,_Traits> &' from 'std::string'
    c:\program files\microsoft visual studio 9.0\vc\include\streambuf(548) : see declaration of 'std:perator =='
    c:\documents and settings\biggestcncfanever\desktop\whatever 2\coding and programming\c+ c++ c#\console practice 1\console practice 1\main.cpp(19) : error C2784: 'bool std:perator ==(const std::istreambuf_iterator<_Elem,_Traits> &,const std::istreambuf_iterator<_Elem,_Traits> &)' : could not deduce template argument for 'const std::istreambuf_iterator<_Elem,_Traits> &' from 'std::string'
    c:\program files\microsoft visual studio 9.0\vc\include\streambuf(548) : see declaration of 'std:perator =='
    c:\documents and settings\biggestcncfanever\desktop\whatever 2\coding and programming\c+ c++ c#\console practice 1\console practice 1\main.cpp(19) : error C2784: 'bool std:perator ==(const std::allocator<_Ty> &,const std::allocator<_Other> &) throw()' : could not deduce template argument for 'const std::allocator<_Ty> &' from 'std::string'
    c:\program files\microsoft visual studio 9.0\vc\include\xmemory(173) : see declaration of 'std:perator =='
    c:\documents and settings\biggestcncfanever\desktop\whatever 2\coding and programming\c+ c++ c#\console practice 1\console practice 1\main.cpp(19) : error C2784: 'bool std:perator ==(const std::allocator<_Ty> &,const std::allocator<_Other> &) throw()' : could not deduce template argument for 'const std::allocator<_Ty> &' from 'std::string'
    c:\program files\microsoft visual studio 9.0\vc\include\xmemory(173) : see declaration of 'std:perator =='
    c:\documents and settings\biggestcncfanever\desktop\whatever 2\coding and programming\c+ c++ c#\console practice 1\console practice 1\main.cpp(19) : error C2784: 'bool std:perator ==(const std::allocator<_Ty> &,const std::allocator<_Other> &) throw()' : could not deduce template argument for 'const std::allocator<_Ty> &' from 'std::string'
    c:\program files\microsoft visual studio 9.0\vc\include\xmemory(173) : see declaration of 'std:perator =='
    c:\documents and settings\biggestcncfanever\desktop\whatever 2\coding and programming\c+ c++ c#\console practice 1\console practice 1\main.cpp(19) : error C2784: 'bool std:perator ==(const std::allocator<_Ty> &,const std::allocator<_Other> &) throw()' : could not deduce template argument for 'const std::allocator<_Ty> &' from 'std::string'
    c:\program files\microsoft visual studio 9.0\vc\include\xmemory(173) : see declaration of 'std:perator =='
    c:\documents and settings\biggestcncfanever\desktop\whatever 2\coding and programming\c+ c++ c#\console practice 1\console practice 1\main.cpp(19) : error C2784: 'bool std:perator ==(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'std::string'
    c:\program files\microsoft visual studio 9.0\vc\include\xutility(2246) : see declaration of 'std:perator =='
    c:\documents and settings\biggestcncfanever\desktop\whatever 2\coding and programming\c+ c++ c#\console practice 1\console practice 1\main.cpp(19) : error C2784: 'bool std:perator ==(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'std::string'
    c:\program files\microsoft visual studio 9.0\vc\include\xutility(2246) : see declaration of 'std:perator =='
    c:\documents and settings\biggestcncfanever\desktop\whatever 2\coding and programming\c+ c++ c#\console practice 1\console practice 1\main.cpp(19) : error C2784: 'bool std:perator ==(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'std::string'
    c:\program files\microsoft visual studio 9.0\vc\include\xutility(2246) : see declaration of 'std:perator =='
    c:\documents and settings\biggestcncfanever\desktop\whatever 2\coding and programming\c+ c++ c#\console practice 1\console practice 1\main.cpp(19) : error C2784: 'bool std:perator ==(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'std::string'
    c:\program files\microsoft visual studio 9.0\vc\include\xutility(2246) : see declaration of 'std:perator =='
    c:\documents and settings\biggestcncfanever\desktop\whatever 2\coding and programming\c+ c++ c#\console practice 1\console practice 1\main.cpp(19) : error C2784: 'bool std:perator ==(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'std::string'
    c:\program files\microsoft visual studio 9.0\vc\include\xutility(2050) : see declaration of 'std:perator =='
    c:\documents and settings\biggestcncfanever\desktop\whatever 2\coding and programming\c+ c++ c#\console practice 1\console practice 1\main.cpp(19) : error C2784: 'bool std:perator ==(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'std::string'
    c:\program files\microsoft visual studio 9.0\vc\include\xutility(2050) : see declaration of 'std:perator =='
    c:\documents and settings\biggestcncfanever\desktop\whatever 2\coding and programming\c+ c++ c#\console practice 1\console practice 1\main.cpp(19) : error C2784: 'bool std:perator ==(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'std::string'
    c:\program files\microsoft visual studio 9.0\vc\include\xutility(2050) : see declaration of 'std:perator =='
    c:\documents and settings\biggestcncfanever\desktop\whatever 2\coding and programming\c+ c++ c#\console practice 1\console practice 1\main.cpp(19) : error C2784: 'bool std:perator ==(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'std::string'
    c:\program files\microsoft visual studio 9.0\vc\include\xutility(2050) : see declaration of 'std:perator =='
    c:\documents and settings\biggestcncfanever\desktop\whatever 2\coding and programming\c+ c++ c#\console practice 1\console practice 1\main.cpp(19) : error C2784: 'bool std:perator ==(const std:air<_Ty1,_Ty2> &,const std:air<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std:air<_Ty1,_Ty2> &' from 'std::string'
    c:\program files\microsoft visual studio 9.0\vc\include\utility(83) : see declaration of 'std:perator =='
    c:\documents and settings\biggestcncfanever\desktop\whatever 2\coding and programming\c+ c++ c#\console practice 1\console practice 1\main.cpp(19) : error C2784: 'bool std:perator ==(const std:air<_Ty1,_Ty2> &,const std:air<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std:air<_Ty1,_Ty2> &' from 'std::string'
    c:\program files\microsoft visual studio 9.0\vc\include\utility(83) : see declaration of 'std:perator =='
    c:\documents and settings\biggestcncfanever\desktop\whatever 2\coding and programming\c+ c++ c#\console practice 1\console practice 1\main.cpp(19) : error C2784: 'bool std:perator ==(const std:air<_Ty1,_Ty2> &,const std:air<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std:air<_Ty1,_Ty2> &' from 'std::string'
    c:\program files\microsoft visual studio 9.0\vc\include\utility(83) : see declaration of 'std:perator =='
    c:\documents and settings\biggestcncfanever\desktop\whatever 2\coding and programming\c+ c++ c#\console practice 1\console practice 1\main.cpp(19) : error C2784: 'bool std:perator ==(const std:air<_Ty1,_Ty2> &,const std:air<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std:air<_Ty1,_Ty2> &' from 'std::string'
    c:\program files\microsoft visual studio 9.0\vc\include\utility(83) : see declaration of 'std:perator =='
    c:\documents and settings\biggestcncfanever\desktop\whatever 2\coding and programming\c+ c++ c#\console practice 1\console practice 1\main.cpp(19) : error C2676: binary '==' : 'std::string' does not define this operator or a conversion to a type acceptable to the predefined operator
    c:\documents and settings\biggestcncfanever\desktop\whatever 2\coding and programming\c+ c++ c#\console practice 1\console practice 1\main.cpp(19) : error C2784: 'bool std:perator ==(const std::istreambuf_iterator<_Elem,_Traits> &,const std::istreambuf_iterator<_Elem,_Traits> &)' : could not deduce template argument for 'const std::istreambuf_iterator<_Elem,_Traits> &' from 'std::string'
    c:\program files\microsoft visual studio 9.0\vc\include\streambuf(548) : see declaration of 'std:perator =='
    c:\documents and settings\biggestcncfanever\desktop\whatever 2\coding and programming\c+ c++ c#\console practice 1\console practice 1\main.cpp(19) : error C2784: 'bool std:perator ==(const std::istreambuf_iterator<_Elem,_Traits> &,const std::istreambuf_iterator<_Elem,_Traits> &)' : could not deduce template argument for 'const std::istreambuf_iterator<_Elem,_Traits> &' from 'std::string'
    c:\program files\microsoft visual studio 9.0\vc\include\streambuf(548) : see declaration of 'std:perator =='
    c:\documents and settings\biggestcncfanever\desktop\whatever 2\coding and programming\c+ c++ c#\console practice 1\console practice 1\main.cpp(19) : error C2784: 'bool std:perator ==(const std::istreambuf_iterator<_Elem,_Traits> &,const std::istreambuf_iterator<_Elem,_Traits> &)' : could not deduce template argument for 'const std::istreambuf_iterator<_Elem,_Traits> &' from 'std::string'
    c:\program files\microsoft visual studio 9.0\vc\include\streambuf(548) : see declaration of 'std:perator =='
    c:\documents and settings\biggestcncfanever\desktop\whatever 2\coding and programming\c+ c++ c#\console practice 1\console practice 1\main.cpp(19) : error C2784: 'bool std:perator ==(const std::istreambuf_iterator<_Elem,_Traits> &,const std::istreambuf_iterator<_Elem,_Traits> &)' : could not deduce template argument for 'const std::istreambuf_iterator<_Elem,_Traits> &' from 'std::string'
    c:\program files\microsoft visual studio 9.0\vc\include\streambuf(548) : see declaration of 'std:perator =='
    c:\documents and settings\biggestcncfanever\desktop\whatever 2\coding and programming\c+ c++ c#\console practice 1\console practice 1\main.cpp(19) : error C2784: 'bool std:perator ==(const std::allocator<_Ty> &,const std::allocator<_Other> &) throw()' : could not deduce template argument for 'const std::allocator<_Ty> &' from 'std::string'
    c:\program files\microsoft visual studio 9.0\vc\include\xmemory(173) : see declaration of 'std:perator =='
    c:\documents and settings\biggestcncfanever\desktop\whatever 2\coding and programming\c+ c++ c#\console practice 1\console practice 1\main.cpp(19) : error C2784: 'bool std:perator ==(const std::allocator<_Ty> &,const std::allocator<_Other> &) throw()' : could not deduce template argument for 'const std::allocator<_Ty> &' from 'std::string'
    c:\program files\microsoft visual studio 9.0\vc\include\xmemory(173) : see declaration of 'std:perator =='
    c:\documents and settings\biggestcncfanever\desktop\whatever 2\coding and programming\c+ c++ c#\console practice 1\console practice 1\main.cpp(19) : error C2784: 'bool std:perator ==(const std::allocator<_Ty> &,const std::allocator<_Other> &) throw()' : could not deduce template argument for 'const std::allocator<_Ty> &' from 'std::string'
    c:\program files\microsoft visual studio 9.0\vc\include\xmemory(173) : see declaration of 'std:perator =='
    c:\documents and settings\biggestcncfanever\desktop\whatever 2\coding and programming\c+ c++ c#\console practice 1\console practice 1\main.cpp(19) : error C2784: 'bool std:perator ==(const std::allocator<_Ty> &,const std::allocator<_Other> &) throw()' : could not deduce template argument for 'const std::allocator<_Ty> &' from 'std::string'
    c:\program files\microsoft visual studio 9.0\vc\include\xmemory(173) : see declaration of 'std:perator =='
    c:\documents and settings\biggestcncfanever\desktop\whatever 2\coding and programming\c+ c++ c#\console practice 1\console practice 1\main.cpp(19) : error C2784: 'bool std:perator ==(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'std::string'
    c:\program files\microsoft visual studio 9.0\vc\include\xutility(2246) : see declaration of 'std:perator =='
    c:\documents and settings\biggestcncfanever\desktop\whatever 2\coding and programming\c+ c++ c#\console practice 1\console practice 1\main.cpp(19) : error C2784: 'bool std:perator ==(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'std::string'
    c:\program files\microsoft visual studio 9.0\vc\include\xutility(2246) : see declaration of 'std:perator =='
    c:\documents and settings\biggestcncfanever\desktop\whatever 2\coding and programming\c+ c++ c#\console practice 1\console practice 1\main.cpp(19) : error C2784: 'bool std:perator ==(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'std::string'
    c:\program files\microsoft visual studio 9.0\vc\include\xutility(2246) : see declaration of 'std:perator =='
    c:\documents and settings\biggestcncfanever\desktop\whatever 2\coding and programming\c+ c++ c#\console practice 1\console practice 1\main.cpp(19) : error C2784: 'bool std:perator ==(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'std::string'
    c:\program files\microsoft visual studio 9.0\vc\include\xutility(2246) : see declaration of 'std:perator =='
    c:\documents and settings\biggestcncfanever\desktop\whatever 2\coding and programming\c+ c++ c#\console practice 1\console practice 1\main.cpp(19) : error C2784: 'bool std:perator ==(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'std::string'
    c:\program files\microsoft visual studio 9.0\vc\include\xutility(2050) : see declaration of 'std:perator =='
    c:\documents and settings\biggestcncfanever\desktop\whatever 2\coding and programming\c+ c++ c#\console practice 1\console practice 1\main.cpp(19) : error C2784: 'bool std:perator ==(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'std::string'
    c:\program files\microsoft visual studio 9.0\vc\include\xutility(2050) : see declaration of 'std:perator =='
    c:\documents and settings\biggestcncfanever\desktop\whatever 2\coding and programming\c+ c++ c#\console practice 1\console practice 1\main.cpp(19) : error C2784: 'bool std:perator ==(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'std::string'
    c:\program files\microsoft visual studio 9.0\vc\include\xutility(2050) : see declaration of 'std:perator =='
    c:\documents and settings\biggestcncfanever\desktop\whatever 2\coding and programming\c+ c++ c#\console practice 1\console practice 1\main.cpp(19) : error C2784: 'bool std:perator ==(const std::_Revranit<_RanIt,_Base> &,const std::_Revranit<_RanIt2,_Base2> &)' : could not deduce template argument for 'const std::_Revranit<_RanIt,_Base> &' from 'std::string'
    c:\program files\microsoft visual studio 9.0\vc\include\xutility(2050) : see declaration of 'std:perator =='
    c:\documents and settings\biggestcncfanever\desktop\whatever 2\coding and programming\c+ c++ c#\console practice 1\console practice 1\main.cpp(19) : error C2784: 'bool std:perator ==(const std:air<_Ty1,_Ty2> &,const std:air<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std:air<_Ty1,_Ty2> &' from 'std::string'
    c:\program files\microsoft visual studio 9.0\vc\include\utility(83) : see declaration of 'std:perator =='
    c:\documents and settings\biggestcncfanever\desktop\whatever 2\coding and programming\c+ c++ c#\console practice 1\console practice 1\main.cpp(19) : error C2784: 'bool std:perator ==(const std:air<_Ty1,_Ty2> &,const std:air<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std:air<_Ty1,_Ty2> &' from 'std::string'
    c:\program files\microsoft visual studio 9.0\vc\include\utility(83) : see declaration of 'std:perator =='
    c:\documents and settings\biggestcncfanever\desktop\whatever 2\coding and programming\c+ c++ c#\console practice 1\console practice 1\main.cpp(19) : error C2784: 'bool std:perator ==(const std:air<_Ty1,_Ty2> &,const std:air<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std:air<_Ty1,_Ty2> &' from 'std::string'
    c:\program files\microsoft visual studio 9.0\vc\include\utility(83) : see declaration of 'std:perator =='
    c:\documents and settings\biggestcncfanever\desktop\whatever 2\coding and programming\c+ c++ c#\console practice 1\console practice 1\main.cpp(19) : error C2784: 'bool std:perator ==(const std:air<_Ty1,_Ty2> &,const std:air<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std:air<_Ty1,_Ty2> &' from 'std::string'
    c:\program files\microsoft visual studio 9.0\vc\include\utility(83) : see declaration of 'std:perator =='
    c:\documents and settings\biggestcncfanever\desktop\whatever 2\coding and programming\c+ c++ c#\console practice 1\console practice 1\main.cpp(19) : error C2676: binary '==' : 'std::string' does not define this operator or a conversion to a type acceptable to the predefined operator


 

Posting Permissions

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