Results 1 to 4 of 4

Thread: C++ Problem

  1. #1
    NOT Banned
    Join Date
    Jan 2007
    Posts
    5,905
    Thanks
    412
    Thanked
    278 times in 253 posts

    C++ Problem

    Haven't done C++ in along time but I just downloaded Visual C++ 2005, problem is my simple code is not compiling.

    Code:
    //Program that adds two numbers
    #include "stdafx.h"
    #include "io.h"
    
    void main()
    {	
    	//Define variables
    	float num1;
    	float num2;
    	float num3;
    	
    	cout << "Enter the first Number: ";
    	cin >> num1;
    	cout << "Enter the second Number: ";
    	cin >> num2;
    	num3 = num1 + num2;
    	cout << "The sum of numbers is: " << num3; endl;
    }
    I keep geting

    error C2065: 'cout' : undeclared identifier
    error C2065: 'cin' : undeclared identifier
    error C2065: 'endl' : undeclared identifier

    i first tried iostream.h, but it says it doesnt exist. Has C++ changed all this time I stopped? I thought iostream.h was the standard.

  2. #2
    Ah, Mrs. Peel! mike_w's Avatar
    Join Date
    Oct 2003
    Location
    Hertfordshire, England
    Posts
    3,326
    Thanks
    3
    Thanked
    9 times in 7 posts
    I've only ever used g++, but I think what you want is:

    #include <iostream>

    Also, cout and cin are in the std namespace - so you'd either need to call std::cout, or type:

    Code:
    using std::cout;
    and similar.

    This compiles fine in g++:

    Code:
    //Program that adds two numbers
    #include <iostream>
    
    int main()
    {	
    	//Define variables
    	float num1;
    	float num2;
    	float num3;
    	
    	std::cout << "Enter the first Number: ";
    	std::cin >> num1;
    	std::cout << "Enter the second Number: ";
    	std::cin >> num2;
    	num3 = num1 + num2;
    	std::cout << "The sum of numbers is: " << num3 << std::endl;
    	return 0;
    }
    Last edited by mike_w; 10-07-2007 at 02:27 PM.
    "Well, there was your Uncle Tiberius who died wrapped in cabbage leaves but we assumed that was a freak accident."

  3. #3
    Not Very Senior Member RavenNight's Avatar
    Join Date
    Aug 2005
    Location
    Somewhere with food
    Posts
    1,188
    Thanks
    5
    Thanked
    11 times in 10 posts
    Try this instead, I think the problem is with the start

    Code:
    //Program that adds two numbers
    #include <stdio.h>
    #include <iostream.h>
    
    void main()
    {	
    	//Define variables
    	float num1;
    	float num2;
    	float num3;
    	
    	cout << "Enter the first Number: ";
    	cin >> num1;
    	cout << "Enter the second Number: ";
    	cin >> num2;
    	num3 = num1 + num2;
    	cout << "The sum of numbers is: " << num3; endl;
    }
    AMD 3700+ San Diego @ 2.8GHz | Zalman CNPS 9500LED + Arctic Cooling MX-1 | Asus A8N-SLi Deluxe + Zalman Northbridge | 1024MB DDR RAM (2 x 512MB Corsair XMS Pro TwinX) | Leadtek nVidia 6600GT 128MB | Creative SoundBlaster X-Fi Xtreme Music | 2x80GB Hitachi Deskstar SATA-II (RAID 0) | Gigabyte 3D Aurora Case | Hiper Type-R 580W Modular | Enermax Ultimate Fan Controller| Microsoft Nautral 4000 | Logitech G5 + fUnc 1030| Ideazon Fang | SpeedLink Medusa 5.1 Surround Headset | Samsung SM913N 19" TFT | Compro DVB-T200

    "Dell? You get better tech support with a cheese sandwich"

  4. #4
    Gentoo Ricer
    Join Date
    Jan 2005
    Location
    Galway
    Posts
    11,048
    Thanks
    1,016
    Thanked
    944 times in 704 posts
    • aidanjt's system
      • Motherboard:
      • Asus Strix Z370-G
      • CPU:
      • Intel i7-8700K
      • Memory:
      • 2x8GB Corsiar LPX 3000C15
      • Storage:
      • 500GB Samsung 960 EVO
      • Graphics card(s):
      • EVGA GTX 970 SC ACX 2.0
      • PSU:
      • EVGA G3 750W
      • Case:
      • Fractal Design Define C Mini
      • Operating System:
      • Windows 10 Pro
      • Monitor(s):
      • Asus MG279Q
      • Internet:
      • 240mbps Virgin Cable
    Quote Originally Posted by RavenNight View Post
    Try this instead, I think the problem is with the start
    Code:
    //Program that adds two numbers
    #include <iostream>
    using namespace std;
    
    void main()
    {	
    	//Define variables
    	float num1;
    	float num2;
    	float num3;
    	
    	cout << "Enter the first Number: ";
    	cin >> num1;
    	cout << "Enter the second Number: ";
    	cin >> num2;
    	num3 = num1 + num2;
    	cout << "The sum of numbers is: " << num3; endl;
    }
    Fixed. the *.h C++ headers are deprechiated due to namespaces being added to the ANSI/ISO C++ standard.
    Quote Originally Posted by Agent View Post
    ...every time Creative bring out a new card range their advertising makes it sound like they have discovered a way to insert a thousand Chuck Norris super dwarfs in your ears...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Problem with Xbox 360 and Samsung TFT
    By JamesD in forum Help! Quick Relief From Tech Headaches
    Replies: 8
    Last Post: 15-11-2007, 01:49 PM
  2. IE7 problem - please help?
    By SkyNetworks in forum Help! Quick Relief From Tech Headaches
    Replies: 5
    Last Post: 20-06-2007, 09:36 PM
  3. CD/DVD drive problem
    By scratched in forum Help! Quick Relief From Tech Headaches
    Replies: 5
    Last Post: 22-03-2006, 04:12 PM
  4. X360 & Samsung SM 930bf Problem
    By JamesD in forum Gaming
    Replies: 0
    Last Post: 08-02-2006, 05:52 PM
  5. gf4 ti4200 screen standby problem.
    By Pete in forum Graphics Cards
    Replies: 3
    Last Post: 14-11-2004, 12:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •