| | |
bug fix
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Apr 2009
Posts: 20
Reputation:
Solved Threads: 0
Hi all,
what is the bug in the following code:
what is the bug in the following code:
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <string> int main() { string str = "Hello World!" cout << str << endl; cout << float x = 5.0f * str << endl; int 65Num = 65; cout << "65Num = " << 65Num << endl; }
Last edited by Ancient Dragon; Apr 11th, 2009 at 10:28 am. Reason: add code tags
•
•
Join Date: Sep 2008
Posts: 90
Reputation:
Solved Threads: 12
•
•
•
•
Hi all,
what is the bug in the following code:
c++ Syntax (Toggle Plain Text)
#include <iostream> #include <string> int main() { string str = "Hello World!" cout << str << endl; cout << float x = 5.0f * str << endl; int 65Num = 65; cout << "65Num = " << 65Num << endl; }
Frist, you miss the
using namespace std; line before the main() function, so the compiler might not recognize cout and string .You also missed a semicolon after
"Hello World!" .Another thing is that you can't declare variables inside
cout , so you should take float x = 5.0f * str outside cout . The multiplication operation of a float type and string type is not even declared, so float x = 5.0f * str has no meaning. The variable 65Num has an "illegal" name - variables' names cannot begin with a digit. Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
![]() |
Similar Threads
- Broken Sword 3 Wine Bottle Bug (Windows Software)
- SQL Injection Attack (Database Design)
- Most frustrating bug (Geeks' Lounge)
- PC Bug Doctor any good? (Windows Software)
- RE: Leaked Windows Source Code (IT Professionals' Lounge)
- bug report: "cniaezi.exe" (Viruses, Spyware and other Nasties)
- CPU at 100% after installing broadband!?! (Windows NT / 2000 / XP)
- Dangerous Bug in HijackThis 1.97.7 Restoral Procedure (Viruses, Spyware and other Nasties)
- Windows explorer problems (Windows NT / 2000 / XP)
- Internet Explorer Bug lets you run DOS commands remotely (Web Browsers)
Other Threads in the C++ Forum
- Previous Thread: Help With Final Output
- Next Thread: destruction of a global variable?
| Thread Tools | Search this Thread |
api array based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






