-
Senior Member
registered user
simple c++ compile problem
Howdy all:
I tried to compile this very simple c++ program using gcc and/or g++.
#include <iostream> // cout, cin
main()
{
char buf[255];
cout << "Please enter a string ==> "; // O/P to STDOUT (screen).
cin >> buf; // I/P from STDIN (keyboard).
cout << "Entered string is " << buf << endl;
}
I get an error saying that cin and cout are not defined. I've tried this on both knoppix 3.3 and knoppix 3.7.
Any ideas?
-
You're using functions (cout, cin) from the standard library but you haven't told the compiler. Add the line "using namespace std;" after your include line. Or preface all your cout/cin/endl etc with std::. This is a basic C++ question, nothing to do with Knoppix etc. You code wouldn't compile on any standard compiler.
-
Senior Member
registered user
Thanks for the info, markb, I'll give your suggestion a try. Even though it wouldn't compile on any standard compiler, I forgot to mention, it compiled and ran just fine with both gcc and g++ on a Debian Woody installation.
Similar Threads
-
By thorby in forum Networking
Replies: 3
Last Post: 02-08-2005, 09:44 PM
-
By Gianluca Impei in forum Networking
Replies: 1
Last Post: 11-03-2004, 05:31 AM
-
By Worm in forum General Support
Replies: 0
Last Post: 02-01-2004, 07:42 PM
-
By Nigel_Tufnel in forum Hdd Install / Debian / Apt
Replies: 2
Last Post: 10-20-2003, 01:09 PM
-
By wangji in forum General Support
Replies: 1
Last Post: 09-19-2003, 05:11 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules

HP - OmniBook 3 16" 2K Touchscreen Laptop - Intel Core Ultra 5 (2025) - 8GB M...
$479.99

8-core 10-core GPU baseboard 8654 to PCIE 5.0x16 GPU expansion baseboard
$377.77

Panasonic Toughbook CF19 MK8 Core i5 3610ME 2.7GHz 12GB RAM 512GB SSD Win 10 Pro
$319.00

Lenovo ThinkPad T480 Core i5-8250u 1.6GHz 8GB 256GB SSD 14" ***Boot to Bios
$110.00

(New) AMD Ryzen 7 5700X 8 Core 16 Thread AM4 Unlocked 3.4 GHz CPU OEM Tray
$169.99

Apple MacBook Air 13.6” M2 8GB 256GB SSD 2022 MLY33LL/A 8‑Core CPU 8‑Core GPU
$529.95

Lenovo LOQ 15 15.6" FHD 144Hz 8-Core i5-12450HX 16GB 512GB SSD GeForce RTX 4050
$799.00

Dell - XPS 13.4" 3K Touchscreen Laptop - Intel Core 5 Series 3 320 2026 - 8GB...
$699.99

Dell Alienware m15 R7 AMD Ryzen 7 6800H 16GB DDR5 1TB SSD RTX 3070 Ti WIN 11 PRO
$920.00

Dell Latitude 14" Laptop Computer Core i5 8GB RAM 128GB SSD Windows 11 WiFi HDMI
$195.31