Learning C/C++

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Learning C/C++

Post 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 ;)
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

looks like you either don't have the standard libraries or you haven't set them up for inclusion (proper directory path)
echo
Forum Newbie
Posts: 4
Joined: Fri Sep 09, 2005 9:39 am

Post 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
User avatar
Joe
Forum Regular
Posts: 939
Joined: Sun Feb 29, 2004 1:26 pm
Location: UK - Glasgow

Post by Joe »

Change:

# include <iostream>

To:

# include <iostream.h>

Should work ok...
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post 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 :)
sheila
Forum Commoner
Posts: 98
Joined: Mon Sep 05, 2005 9:52 pm
Location: Texas

Post 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.
Last edited by sheila on Mon Sep 19, 2005 4:46 am, edited 1 time in total.
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post 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:
Shaneckel
Forum Commoner
Posts: 48
Joined: Fri Sep 23, 2005 3:46 am
Location: Pittsburgh, PA

Post 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.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post 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
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post 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.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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 :)
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post 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)
Post Reply