Hi guys,
Here we go again, new Tips.........
Multi-line string / untermainated string
1. Example This short program
#include <iostream>
#include <string>
using namespace std;
int main( )
{
cout << "Slash is my buddy;
cout << " and so is Fear" << endl;
}
causes these compiler errors string.
cpp:7:12: warning: multi-line string literals are deprecated string.cpp: In function `int main()':
string.cpp:7: `so' undeclared (first use this function) string.cpp:7: (Each undeclared identifier is reported only once for each function it appears in.) string.cpp:7: parse error before `Mary' string.cpp:8:28: warning: multi-line string literals are deprecated string.cpp:8:28: missing terminating " character string.cpp:7:12: possible start of unterminated string literal
Or when your using an advanced compiler it would throw you the following error:
cpp:6: error: missing terminating " character
2. Meaning
The compiler thinks that you are trying to create a multi-line string which is no longer a supported feature of the language
3. Usual Causes
1. You're missing a quote mark at the end of one of your strings
Comparison between signed and unsigned integer expressions
1. Example xyz.cpp: In function `int main()': zyz.cpp:54: warning: comparison between signed and unsigned integer expressions
2. Meaning
This is a compiler warning that you are comparing ( ==, <, > etc) an integer expression (may be poitive, negative or zero) and an unsigned integer expression (may be positive or zero, but not negative).
3. Usual Causes
1. In our projects, this warning usually arises in a for-loop which is looping through all elements of a vector. For example, assuming "grades" is a vector of some kind, the warning is generated by this code
for (int i = 0; i < grades.size( ); i++
{
// body of the for-loop here
}
because vector's size( ) function returns an unsigned int. To fix this problem simply define 'i' as an unsigned int too, as in
for( unsigned int i; i < grades.size( ); i++)
Suggest parentheses around assignment used as truth value
1. Example xyz.cpp: In function `int main()': xyz.cpp:54: warning: suggest parentheses around assignment used as truth value.
2. Meaning
This is a suggestion from the compiler that you add parenthesis around an assignment statement that used as a condition in an if/while/for, etc. This is usually NOT what you meant to do.
3. Usual Causes
1. This warning is usually caused by using "=" instead of "==" in an if-statement as in
if ( length = maxLength ) /* when what you meant was as shown below */
if ( length == maxLength)
Guys any doubts please ask!!!!😁
Next would be various Pitfalls in C++.........;-)
-Arvind(slashfear)