No output displayed when a pointer is defined; - c++

#include <iostream>
using namespace std;
int main()
{
int val = 8;
int *point = &val;
cout << val << *point << endl;
}
I wrote a fairly straightforward program to print out the value of a variable first by using the variable name then by using a pointer to the variable. For some unknown reason though, no output is printed to the console.
However, if I run the same code line by line in the debugger, I get the expected output (88).
Since this problem is likely specific to me, I'll add that I'm using Eclipse Kepler with the MinGW compiler on a 64 bit system. Any help on how I can solve this problem and get pointers to function normally would be highly appreicated.

I found your answer here
and since your code and debugger is correct - this is what you the post recommends that you do:
[1] Uninstall
- Removed all traces of Eclipse (64-bit).
- Removed all traces of MinGW (and/or Cygwin).
- Removed all traces of Java (SDK and JRE).
[2] Restart PC
[3] Install
- Installed latest Java JDK (includes the JRE) 32-bit.
- Installed Eclipse IDE (Java Edition) 32-bit.
- Installed MinGW (with Msys).
- Installed the necessary CDT tools from within Eclipse.
However, as an avid Xcode/Jetbrains user I would recommend that you check your settings first because those are the funnest to debug.

Should work this way:
add stdafx.h
return 0 at termination

Related

IDE showing blank console

It's been days since I try to make my IDE (Code::Blocks version 13.12, I tried on 10.05 too) work. Any program (including a simple Hello World! program) I would make would show a black console showing nothing but an " _ ". I have made an exception in my antivirus (Avast!) for the file containing the IDE) but the same thing happens . I have tried re-installing twice, i have tried resetting the compiler and debugger's settings to default, auto-detecting toolchain executables ,but the same thing happens.
I have tried rebooting my computer several times, same thing happens.
I would like to know what I can do to solve this problem , because I don't want to get another complicated compiler (I am a beginner,) , as Code::Blocks fits my needs perfectly.
The following codes produces a blank console:
#include <iostream>
int main()
{
std::cout << "Hello world!\n";
return 0;
}
I had the same exact problem, with Eclipse, Visual Studio and then with Code::Blocks (I tested them all). I suggest you follow this video tutorial after you confirm the problem persists with a second IDE : https://www.youtube.com/watch?v=zOGU8fC3bvU&index=6&list=LLHcXdIeBMN4XYRZAk4IeXmg&spfreload=10 . It will take you step by step on how to install a given compiler.

C++ HelloWorld not printing correctly

I just installed c/c++ development tools for my eclipse and everything is working except no text is being printed in the console when I run the hello world program, but I receive no errors. I'm really stumped, anyone know why this is?
Edit:
Ok I realized if that debug it, it works correctly, but not if I run it, any ideas there?
Are you using a 64-bit version of Eclipse? If so, that might be your problem. The 64-bit version doesn't do console output. sigh Try downgrading to the 32-bit version.
On SO, check this question.
On the Eclipse forums, check this thread.
Does a window pop up then disappear? It could be printing it in console then closing as soon as it hits the end of the code...
try to make your code like this:
#include <iostream>
#include <conio.h>
using namespase std;
int main()
{
cout << "helllo, world" << endl;
getch();
return 0;
}
You must set the environment so the eclipse can find the c++ compiler.
Go to Computer and right click Properties -> advanced system settings -> enviroment variables.
Scroll down in system variables and find the path (it is named so). Press edit and append in the path the value C:\MinGW\bin;C:\MinGW\msys\1.0\bin;. You will have something like C:\MinGW\bin;C:\MinGW\msys\1.0\bin;C:\programfiles........
Then start again the eclipse the problem should have been solved.

Eclipse C++ Running/Debugging problems with console IO

I've been trying to get into C++ programming with Eclipse, but I'm having problems setting up Eclipse.
I have MinGW installed and in the environment path, and I created the simple C++ project with the following source code:
#include <iostream>
int main(void)
{
std::cout << "what is your name? ";
std::string name;
std::cin >> name;
std::cout << "Hello, " << name << std::endl;
std::cin.ignore();
return 0;
}
After successfully building the project (both debug and release configurations), I click the run button and there's no output. The program terminates immediately. I've also tried running in debug mode, but then it will wait for me to type in a name, then display all the output. example console:
scott
what is your name? Hello, scott
I've tried this with both the 32 and 64 bit Windows versions of Eclipse Helios and both versions have the same behavior. Does anyone know what is going on and how to fix this?
I've run the program from the command-line and it works as intended.
edit: After some tinkering around, I found that by copying the MinGW dll's into the same folder as the executable the program will run in Eclipse just fine. Is there an alternative method to have Windows find the dll's in MinGW's bin folder rather than have to copy them over each time?
Is there an alternative method to have Windows find the dll's in MinGW's bin folder rather than have to copy them over each time?
Set the PATH environment variable in the run configuration settings (Run -> Run Configurations... -> Environment).

playing with GCC 4.6 on windows

I am very pleased to find out that GCC 4.6 supports the range-based for loop. I found an experimental release of MinGW 4.6 on xvidvideo.ru, is that a well-known, reliable website? What other options do I have (besides compiling myself from source code)?
I wanted to try out GCC 4.7 using the latest Code::Blocks under Windows 7.
Here's how I did it for myself, YMMV:
I downloaded the latest Equation GCC file at:
ftp://ftp.equation.com/gcc/ and installed it under the directory C:\gcc\ on my local machine. The installer makes the necessary changes to the path environment variable. Logging off and on will pick them up.
I downloaded the Code::Blocks latest nightly build at: http://forums.codeblocks.org/index.php?board=20.0
and followed the setup instructions.
After following the setup instructions (including about the needed DLL files), and starting C::B for the first time;
I chose 'GNU GCC Compiler', and 'Set as default' for the 'Compilers auto-detection' window.
Under the 'Settings > Compiler... > Compiler settings' tab:
I ticked the 'Have g++ follow the coming C++0x ISO C++ language standard [-std=c++0x]' checkbox on.
Under the 'Settings > Compiler... > Toolchain executables' tab:
I changed the 'Compiler's installation directory' entry field to C:\gcc\bin\.
I changed the names of these files physically located in the C:\gcc\bin\ directory
i686-pc-mingw32-gcc.exe -=to=- mingw32-gcc.exe
i686-pc-mingw32-g++.exe -=to=- mingw32-g++.exe
make.exe -=to=- mingw32-make.exe
to match the listed name requirements in Code::Blocks. You can simply browse to set the correct files (I just personally preferred renaming to match C::B's entries).
If everything went correctly, you should be able to create this program:
#include <iostream>
#include <vector>
int main() {
using namespace std;
vector<int> my_vec = { 1, 2, 3, 4, 5 };
for (auto x : my_vec) {
cout << x << endl;
}
}
and run it OK under Code::Blocks with F9.
Thanks to everyone for all the excellent work put into bringing this great new language to us. Happy C++0x computing!
Bud Alverson
(sorry for the very basic nature of this post) :)
I'm not really familiar with the site you linked as it's in Russian. The only other place I've found that offers current snapshots of GCC's build is from Equation Solution. I downloaded gcc4.5.1 from there and it's been working fairly well for me. I haven't tried the 4.6.x release yet however. Rumor has it that gcc 4.6.x is slower than its predecessors.
Please do report back what kind of results you're seeing if you do decide experimenting. I'm curious about what improvements they've done in the 4.6.x series.

OS X 10.6.4 + Eclipse 3.5 + latest CDT not outputting cout/printf to console

I spend most of my time in Eclipse these days, so I thought I would check out what Eclipse's C++ support was like (I usually use Xcode on Mac and Visual Studio for Windows).
I found the CDT package for Eclipse 3.5, so I installed it.
Everything installed properly and the default C++ "Hello World" project compiled nicely, however for the life of me I can't get any application output piped to the console. I've tried everything, and searched around for solutions, but it seems I'm not the only one. Most have trouble in Windows, but I haven't seen a lot of issues with OS X.
Of course, if I run the compiled output in a bash shell, it displays output properly.
This is how simple the default app is:
#include <iostream>
using namespace std;
int main() {
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
printf("Hello world");
return 0;
}
Any ideas?
Cheers,
Shane
Just tried this in Helios 3.6 and it works. Must be a 3.5 problem.