User forums > Help
Code::Blocks/Borland Compiler 5.5/ cout << stringVar error [solved]
Joe:
Greeting All!
Code::Blocks is exactly what I was looking for, and you guys did a great job!
I have an issue with a simple C++ program, using a string variable. Below, I have included the code from a file named StringTest.cpp:
----------- Code: StringTest.cpp -----------------------
1. #include <iostream>
2. #include <string>
3.
4. int main()
5. {
6. using namespace std;
7.
8. string aName = "Hello World";
9. cout << "Hello World\n" << endl;
10. cout << aName;
11.
12. return 0;
13. }
--------------------------------------------------------
The program builds with no errors or warnings. Below I have included the ouput from the build:
-------------- Build: Debug in StringWork ---------------
bcc32.exe -q -w -x -v -IC:\Borland\BCC55\Include -oobj\Debug\StringTest.obj -c StringTest.cpp
StringTest.cpp:
ilink32.exe -q -ap -v -LC:\Borland\BCC55\lib -LC:\Borland\BCC55\lib\psdk c0x32 obj\Debug\StringTest.obj ,bin\Debug\StringWork.exe,,cw32mt.lib import32.lib ,,
Output size is 119.50 KB
Process terminated with status 0 (0 minutes, 0 seconds)
0 errors, 0 warnings
---------------------------------------------------------
When I run the executable from within Code::Blocks (or by just double clicking the .exe file) I first get an error from Windows that says:
-------------- Error: Windows XP Home SP3----------------
StringWork.exe has encountered a problem and needs to close. We are sorry for the inconvenience.
---------------------------------------------------------
Then the console, started by Code::Blocks, displays:
------------- Information: Code::Blocks 10.05 -----------
Process returned -1073741819 (0xC0000005) execution time : 12.344 s
Press any key to continue.
---------------------------------------------------------
If I comment out line 10 [cout << aName;], the program compiles and runs as expected.
OS: Windows XP Home SP3
Code::Blocks: 10.05
Compiler: Borland 5.5, 5.82 (sp1, sp2)
Thank you for your help.
stahta01:
Correction, your code fails the C::B sample code works; your C++ code has a problem and BCC 5.1 has a bug.
The C::B sample code Works for me using C::B 10.05 and Borland 5.5
I saw no difference from your build log; my Borland installation is in "C:\GreenApps\BCC55".
OS Windows 7 32 Bit; I have some of the Win 7 security turned off.
Tim S.
--- Code: ---bcc32.exe -q -w -x -v -IC:\GreenApps\BCC55\Include -oobj\Debug\main.obj -c main.cpp
main.cpp:
ilink32.exe -q -ap -v -LC:\GreenApps\BCC55\Lib -LC:\GreenApps\BCC55\Lib\PSDK c0x32 obj\Debug\main.obj ,bin\Debug\testbcc55.exe,,cw32mt.lib import32.lib ,,
Output size is 119.00 KB
--- End code ---
stahta01:
--- Code: ---using namespace std;
--- End code ---
The using must NOT be inside a function; BCC 5.5 has a bug. I suggest using a newer Compiler.
The fixed code worked OK using BCC 6.1.
This IS NOT an Code::Blocks issue; this thread is likely to be locked.
Tim S.
Joe:
Thank you for your quick response Tim.
1.) The code sample I posted compiles and runs perfectly from the command line.
2.) Based on your second response, I have moved [using namespace std;] to below the includes and above the [int main()] declaration.
Recompiling the program and running produces the same error as previously described.
Which forum should this be posted in Tim?
stahta01:
--- Quote from: Joe on November 29, 2010, 01:34:50 am ---1.) The code sample I posted compiles and runs perfectly from the command line.
--- End quote ---
Are you sure, it works from the Command line running the exact same command to Compile and Link?
It FAILS the same way for me on the command line.
--- Quote from: Joe on November 29, 2010, 01:34:50 am ---Which forum should this be posted in Tim?
--- End quote ---
If it is a compiler bug, you need to find a site that supports the Compiler!
Tim S.
Navigation
[0] Message Index
[#] Next page
Go to full version