Compiling Issues with Accelerated C++

Aug 7, 2010 at 4:33pm
Hey guys, this is my first post of this forum and hopefully not my last, but I have just one question:

Which compiler did you use for the book Accelerated C++?

I am using Code::Blocks with the Borland C++ Compiler and on chapters 1.1, I am having compiler issues.

Thanks!
Aug 7, 2010 at 5:24pm
I didn't use any compiler for the book Accelerated C++
;^)
Post code & errors please
Aug 7, 2010 at 7:33pm
Okay so a big update!

I just changed my Compiler to Dev-C++ and the program works. Here is the code:

#include <iostream>
#include <string>
using namespace std; // I did this to save time from all of the "std::cout/cin" stuff.

int main()
{
cout<< "Please enter your first name: \n";
string name;
cin>> name;
cout<< "Hello, " << name << "! \n";
return 0;
}

When I compile and execute the program, it opens and closes rapidly.

Thanks!
Last edited on Aug 7, 2010 at 7:36pm
Aug 7, 2010 at 8:06pm
Don't use Dev-C++ it's too old.
Borland C++ is even older.
Aug 7, 2010 at 9:00pm
Please use [code] tags.

And does the program close before or after you type the name?
Aug 7, 2010 at 9:02pm
Bazzy - Okay well what do you suggest.

wasabi - Okay sorry, and it's after I type the name.
Aug 7, 2010 at 9:12pm
I use CodeBlocks 10.05 wit GCC 4.5.0
see http://www.cplusplus.com/forum/articles/7263/
Aug 7, 2010 at 9:14pm
Well, after you type the name, the program does exactly what you tell it to do. It displays the name and then it ends and closes itself. You need to ask the program do stop, the best way is to put
1
2
getch();
getch();
after the cout line.
Aug 7, 2010 at 9:16pm
_getch();

will need you to include the conio.h header file, same as you include <iostream> to use cout and cin
Aug 7, 2010 at 9:23pm
So why wouldn't they tell me this in the book?
Aug 7, 2010 at 9:30pm
because conio.h is not standard, it's old and not portable
btw http://www.cplusplus.com/forum/articles/7312/
Aug 7, 2010 at 10:10pm

wow.. thanks for the update..

anytime I've used flush though, even if there is nothing in the buffer, it skips right over..

to be able to use any key, you could just use cin.ignore(1, '\n'); right?
Topic archived. No new replies allowed.