| View previous topic :: View next topic |
| Author |
Message |
RusBoi Master Cheater
Reputation: -1
Joined: 07 Apr 2008 Posts: 343
|
Posted: Thu Dec 25, 2008 12:10 pm Post subject: [C++] Error problem |
|
|
Well iI just started learning C++ couple of days ago and I ran in to this problem.
My Code
| Quote: | // This is a comment
// This program will accept numbers and display their sum
#include <C++2.h>
using namesplace std;
void main()
{
// define variable
float num1;
float num2;
float total;
//Enter date for the variable
cout << "Enter a value for the first variable: ";
cin >> num1;
cout << "Enter a value for the first variable: ";
cin >> num2;
// Add the two numbers together
total = num1 + num2;
//Display the result
cout << "The sum of the numbers = " << total;
} |
My Header
| Quote: | | #include <iostream> |
This is the Output
| Quote: | 1>------ Build started: Project: C++2, Configuration: Debug Win32 ------
1>Compiling...
1>C++2.cpp
1>c:\documents and settings\chris\my documents\visual studio 2008\projects\c++2\c++2\c++2.cpp(4) : fatal error C1083: Cannot open include file: 'C++2.h': No such file or directory
1>Build log was saved at "file://c:\Documents and Settings\Chris\My Documents\Visual Studio 2008\Projects\C++2\C++2\Debug\BuildLog.htm"
1>C++2 - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== |
What am I doing wrong? All the files are in the same folder as in "C++2.cpp" and "C++2.h" so idk what I'm doing wrong.
_________________
|
|
| Back to top |
|
 |
BanMe Master Cheater
Reputation: 0
Joined: 29 Nov 2005 Posts: 375 Location: Farmington NH, USA
|
Posted: Thu Dec 25, 2008 12:12 pm Post subject: |
|
|
when including your own header file use qoutes around the names
ex: #include "C++2.h"
regards BanMe
|
|
| Back to top |
|
 |
RusBoi Master Cheater
Reputation: -1
Joined: 07 Apr 2008 Posts: 343
|
Posted: Thu Dec 25, 2008 12:15 pm Post subject: |
|
|
OK well I have done that, it seems it fixed the problem but now i get this for my Output.
| Quote: | 1>------ Build started: Project: C++2, Configuration: Debug Win32 ------
1>Compiling...
1>C++2.cpp
1>c:\documents and settings\chris\my documents\visual studio 2008\projects\c++2\c++2\c++2.cpp(5) : error C2146: syntax error : missing ';' before identifier 'std'
1>c:\documents and settings\chris\my documents\visual studio 2008\projects\c++2\c++2\c++2.cpp(5) : error C2873: 'namesplace' : symbol cannot be used in a using-declaration
1>c:\documents and settings\chris\my documents\visual studio 2008\projects\c++2\c++2\c++2.cpp(5) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\documents and settings\chris\my documents\visual studio 2008\projects\c++2\c++2\c++2.cpp(5) : error C2365: 'std' : redefinition; previous definition was 'namespace'
1>c:\documents and settings\chris\my documents\visual studio 2008\projects\c++2\c++2\c++2.cpp(14) : error C2065: 'cout' : undeclared identifier
1>c:\documents and settings\chris\my documents\visual studio 2008\projects\c++2\c++2\c++2.cpp(15) : error C2065: 'cin' : undeclared identifier
1>c:\documents and settings\chris\my documents\visual studio 2008\projects\c++2\c++2\c++2.cpp(16) : error C2065: 'cout' : undeclared identifier
1>c:\documents and settings\chris\my documents\visual studio 2008\projects\c++2\c++2\c++2.cpp(17) : error C2065: 'cin' : undeclared identifier
1>c:\documents and settings\chris\my documents\visual studio 2008\projects\c++2\c++2\c++2.cpp(22) : error C2065: 'cout' : undeclared identifier
1>Build log was saved at "file://c:\Documents and Settings\Chris\My Documents\Visual Studio 2008\Projects\C++2\C++2\Debug\BuildLog.htm"
1>C++2 - 9 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== |
My Code NEW:
| Quote: | // This is a comment
// This program will accept numbers and display their sum
#include "C++2.h"
using namesplace std;
void main()
{
// define variable
float num1;
float num2;
float total;
//Enter date for the variable
cout << "Enter a value for the first variable: ";
cin >> num1;
cout << "Enter a value for the first variable: ";
cin >> num2;
// Add the two numbers together
total = num1 + num2;
//Display the result
cout << "The sum of the numbers = " << total;
}
|
My Header NEW:
| Quote: | #include <iostream>
|
_________________
|
|
| Back to top |
|
 |
Heartless I post too much
Reputation: 0
Joined: 03 Dec 2006 Posts: 2436
|
Posted: Thu Dec 25, 2008 12:21 pm Post subject: |
|
|
| Code: | // This is a comment
// This program will accept numbers and display their sum
#include <iostream>
using namespace std;
void main()
{
// define variable
float num1;
float num2;
float total;
//Enter date for the variable
cout << "Enter a value for the first variable: ";
cin >> num1;
cout << "Enter a value for the first variable: ";
cin >> num2;
// Add the two numbers together
total = num1 + num2;
//Display the result
cout << "The sum of the numbers = " << total;
} |
Just take out your header file and include iostream in your .cpp. Also please use [code][\code] and not the quotes.
And it is
| Code: | | using namespace std; |
you just spelled it wrong.
_________________
What dosen't kill you, usually does the second time. |
|
| Back to top |
|
 |
RusBoi Master Cheater
Reputation: -1
Joined: 07 Apr 2008 Posts: 343
|
Posted: Thu Dec 25, 2008 12:25 pm Post subject: |
|
|
THANK YOU ! IT WORKS !
_________________
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Thu Dec 25, 2008 4:22 pm Post subject: |
|
|
| btw, int main()
|
|
| Back to top |
|
 |
ElectroFusion Grandmaster Cheater
Reputation: 0
Joined: 17 Dec 2006 Posts: 786
|
Posted: Thu Dec 25, 2008 5:16 pm Post subject: |
|
|
btw my coochie, void main will work.
_________________
| qwerty147 wrote: |
| ghostonline wrote: |
what world are you in?
|
bera
but i live in NZ
|
|
|
| Back to top |
|
 |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
|
| Back to top |
|
 |
crayzbeef Expert Cheater
Reputation: 0
Joined: 21 Jan 2007 Posts: 101
|
Posted: Fri Dec 26, 2008 10:39 am Post subject: |
|
|
| For fucks sake, Who taught you this ? void main? Are you shitting me?
|
|
| Back to top |
|
 |
xV I post too much
Reputation: 1
Joined: 03 Jan 2008 Posts: 3783 Location: Seattle
|
Posted: Fri Dec 26, 2008 3:54 pm Post subject: |
|
|
| crayzbeef wrote: | | For fucks sake, Who taught you this ? void main? Are you shitting me? |
All the tuts I've read tell me "int main ()" I never even knew "void main ()" existed until now. Yeah, still learning.
|
|
| Back to top |
|
 |
Overload Master Cheater
Reputation: 0
Joined: 08 Feb 2008 Posts: 293
|
Posted: Fri Dec 26, 2008 5:23 pm Post subject: |
|
|
| ElectroFusion wrote: | | btw my coochie, void main will work. |
I thought even YOU would learn not to use this by now. But i guess your wrong. You're stupidity extends past my comprehension.
_________________
Blog
| Quote: | Rhys says:
you can be my maid
Rhys says:
ill buy you a french maid outfit
Tyler says:
Sounds good
Rhys says:
ill hold you to that |
|
|
| Back to top |
|
 |
|