![]() |
| ||
| c++ compilation error hi, i am basically a newbie to C++ and tried to make this simple math program but came acroos this error and don't know how to resolve it: #include <iostream>the error is saying: limac@limac-kubuntu:~/Desktop$ g++ -o math math.cpp math.cpp:15:14: warning: multi-character character constant math.cpp:23:20: warning: character constant too long for its type math.cpp:31:20: warning: character constant too long for its type math.cpp:39:20: warning: character constant too long for its type math.cpp: In function ‘int main()’: math.cpp:10: error: ‘Add’ was not declared in this scope math.cpp:15: warning: overflow in implicit constant conversion math.cpp:15: error: could not convert ‘input.std::basic_string<_CharT, _Traits, _Alloc>::operator= [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>](100)’ to ‘bool’ math.cpp:23: warning: overflow in implicit constant conversion math.cpp:23: error: could not convert ‘input.std::basic_string<_CharT, _Traits, _Alloc>::operator= [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>](116)’ to ‘bool’ math.cpp:31: warning: overflow in implicit constant conversion math.cpp:31: error: could not convert ‘input.std::basic_string<_CharT, _Traits, _Alloc>::operator= [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>](121)’ to ‘bool’ math.cpp:39: warning: overflow in implicit constant conversion math.cpp:39: error: could not convert ‘input.std::basic_string<_CharT, _Traits, _Alloc>::operator= [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>](101)’ to ‘bool’ limac@limac-kubuntu:~/Desktop$ if anyone can identify the error and inform me, I'd really appreciate that! Thx |
| ||
| Re: c++ compilation error Add, Subtract, and etc are strings. You wrote 'Add' it's suppose to be "Add". All strings are denoted with " ", chars are denoted with ' '. |
| ||
| Re: c++ compilation error There are a few issues. In the line, "string input = Add;", I don't think you need the Add there. All you need to do is initialize the string input. The line if(Add) needs to be changed to "if(input == "Add"). Additionally, every if line needs to use ==, not =. Lastly, all you need to do is use double quotes instead of single ones. |
| ||
| Re: c++ compilation error string input = Add;Add is undeclare variable. I know you want to assign string of "Add" to input, so you change it to "Add". (Remember "...." is string, without those double quote, it is a variable)if (Add)What kind of condition is that? What is Add? else if (input = 'Subtract')
|
| ||
| Re: c++ compilation error correct .. you need to specify string in double quotes...and use double equal to(==) sign to check equality in if() |
| ||
| Re: c++ compilation error The following is pretty much useless: string input = Add; Change it to the following to just declare the var. string input; The entered value (Add, Subtract, Multiply, Divide) will be placed in the var input. This means, you want to check which value was entered. You could use the following to check it: if (!strcmp(input.c_str(), "Add")) Hope this helps. Kind regards, Erik |
| All times are GMT -4. The time now is 3:51 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC