Page 1 of 1

Learning C/C++

Posted: Thu Sep 08, 2005 7:59 am
by s.dot
So, I decided I want to learn C. And I have a couple of n00bish questions.

My Code:

Code: Select all

# include <iostream>

using namespace std;

int main()
{
  cout<<"HEY, you, I'm alive! Oh, and Hello World!\n";
  cin.get();
}
That was copied straight from the web page.

When I compile using Borland Command Compiler bcc32 test.cpp, I get the following results:

Code: Select all

C:\Borland\BCC55\Bin>bcc32 test.cpp
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
test.cpp:
Error E2209 test.cpp 1: Unable to open include file 'iostream'
Error E2282 test.cpp 3: Namespace name expected
Error E2451 test.cpp 7: Undefined symbol 'cout' in function main()
Error E2451 test.cpp 8: Undefined symbol 'cin' in function main()
*** 4 errors in Compile ***
Someone guide me in the right direction ;)

Posted: Thu Sep 08, 2005 8:56 am
by feyd
looks like you either don't have the standard libraries or you haven't set them up for inclusion (proper directory path)

Posted: Fri Sep 09, 2005 9:42 am
by echo
when I used borland c++, we used ye olde c++ syntax

Code: Select all

# include <iostream.h>

int main()
{
  cout<<"HEY, you, I'm alive! Oh, and Hello World!\n";
  cin.get();
  return 0;
}
try that

Posted: Fri Sep 09, 2005 9:44 am
by Joe
Change:

# include <iostream>

To:

# include <iostream.h>

Should work ok...

Posted: Sat Sep 17, 2005 2:00 am
by s.dot
Okay, my sound like a dumb question.. but where can I download the C/C++ libraries? I thought it was going to be like magic. COMPILE AND APPEAR! :-D

Posted: Sat Sep 17, 2005 2:16 am
by n00b Saibot
For starting you can you use the old & popular Turbo C/C++ IDE. It comes with all the libraries and the also the one I like most - graphics.h library :)

Posted: Sat Sep 17, 2005 9:41 am
by sheila
scrotaye wrote:but where can I download the C/C++ libraries? I thought it was going to be like magic. COMPILE AND APPEAR! :-D
If you're using Borland you should have all the standard libraries, and you should be able to use the IDE. I'm confused.

Posted: Mon Sep 19, 2005 3:28 am
by n00b Saibot
sheila wrote:
scrotaye wrote:but where can I download the C/C++ libraries? I thought it was going to be like magic. COMPILE AND APPEAR! :-D
If you're using Borland you should have all the standard libraries, and you should be able to use the IDE. I'm confused.
So is he :lol:

Posted: Mon Sep 26, 2005 1:40 am
by Shaneckel

Code: Select all

#include <iostream> 
using namespace std;

int main()
{

   cout << "Woot-cheese" << endl;

}
this is what I've come up with, it dosen't execute. I've been trying to learn it too.

Posted: Mon Sep 26, 2005 3:11 am
by timvw
The file compiles well here... So it must be a problem with your config

Code: Select all

#include <iostream>
using std::cout;
using std::endl;

int main()
{
    cout << "hello world" << endl;
    // uh-oh portability issue
    system("pause");
    return 0;
}

Code: Select all

timvw@madoka:~/src/3ti/cpp$ g++ -Wall opgave1.cpp
timvw@madoka:~/src/3ti/cpp$ ./a.out
hello world
sh: line 1: pause: command not found
But on windows you could consider http://www.bloodshed.net/devcpp.html.

Posted: Mon Sep 26, 2005 6:24 am
by Chris Corbyn
You specify the "int" type but don't return an integer ;)

I've not used Borland, I've only used GNU C++ but iostream.h should be bakward compatible where just <iostream> could give errors. The basic libraries should be there and iostream is pretty basic :P

I'm also just learning C++ on occassions where my mind needs something different than PHP in order to not turn to mush :P

Posted: Mon Sep 26, 2005 7:57 am
by Charles256
was cin.get() your way of pausing the system? that's normally not even needed when you compile:-D later on when you run an exe file yes, but not when compiling. also, i'd recommend dev-c++, it works like a charm almost every time:) and as he said ALWAYS end int main with return 0; that should always be at the end of your int main function. :-D

Posted: Mon Sep 26, 2005 8:07 am
by n00b Saibot
d11wtq wrote:You specify the "int" type but don't return an integer
but he returns :arrow:
return 0;
system("pause") will break because it calls to DOS command "Pause" which is not available on *NIX ;)
I have always said that do not use/rely on native system calls if the program has to be portable since it will break on other systems/OS.

Posted: Mon Sep 26, 2005 8:16 am
by Chris Corbyn
Sorry I was referring to the original post regarding the int return :)

I'm now looking forward to getting home from work and playing around with a bit of GNU C++ myself :)

Posted: Mon Sep 26, 2005 8:41 am
by n00b Saibot
d11wtq wrote:I'm now looking forward to getting home from work and playing around with a bit of GNU C++ myself :)
I love making cute graphics programs outta C++ 8)