Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[C++] Compiling errors (take a look)
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
manc
Grandmaster Cheater
Reputation: 1

Joined: 16 Jun 2006
Posts: 551

PostPosted: Wed Jul 02, 2008 12:56 am    Post subject: [C++] Compiling errors (take a look) Reply with quote

Code:
#include <iostream>

void main()

{
//define variables
float num1;
float num2;
float total;
//enter data for the variables
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 << endl;
}



I followed a video tutorial ( he was using Microsoft visual studios Version 6 ) and well, I have the same exact code as he does in the tut, but his old compiler gives no errors, mine however gives:

Line 5: 'main' must return 'int'
(In function 'int main(...)'

Line 11: 'cout' undeclared (first use this function)
(Each undeclared identifier is reported only once for each function it appears in.)

Line 12: 'cin' undeclared (first use this function)

Line 20: 'endl' undeclared (first use this function)

So I'm guessing I need to 'declare' these functions, but how exactly do I do so? And I have no idea on line 5. Not a mention of 'int' in the tutorial.
Any help would be much appreciated.

_________________
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Wed Jul 02, 2008 1:01 am    Post subject: Reply with quote

int main()

std::cout
std::cin
std::endl

the tutorial is probably ancient

Code:
#include <iostream>

float num1;
float num2;
float total;

int main()
{
   std::cout << "Enter a value for the first variable: ";
   std::cin >> num1;
   std::cout << "Enter a value for the first variable: ";
   std::cin >> num2;
   total = num1 + num2;

   std::cout << "The sum of the numbers = " << total << std::endl;
   return 0;
}
Back to top
View user's profile Send private message
manc
Grandmaster Cheater
Reputation: 1

Joined: 16 Jun 2006
Posts: 551

PostPosted: Wed Jul 02, 2008 1:10 am    Post subject: Reply with quote

Ok, all thats left is the undeclared errors.

Where exactly does the
Code:
std::cout
std::cin
std::endl
part go? Just anywhere in the brackets? I'll experiment meanwhile.

EDIT: FUCK IT, I'm trying a different tut.

_________________
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Wed Jul 02, 2008 2:58 am    Post subject: Reply with quote

manc wrote:
Ok, all thats left is the undeclared errors.

Where exactly does the
Code:
std::cout
std::cin
std::endl
part go? Just anywhere in the brackets? I'll experiment meanwhile.

EDIT: FUCK IT, I'm trying a different tut.


What? Just prefix std:: to cout, etc. I even posted a damn example.
Back to top
View user's profile Send private message
Noz3001
I'm a spammer
Reputation: 26

Joined: 29 May 2006
Posts: 6220
Location: /dev/null

PostPosted: Wed Jul 02, 2008 3:25 am    Post subject: Reply with quote

If you still get errors add "using namespace std;". It includes the whole thing but it's the only thing which works in some cases. (Code::Blocks?...)
Back to top
View user's profile Send private message MSN Messenger
Caelestis
Expert Cheater
Reputation: 0

Joined: 03 May 2007
Posts: 153

PostPosted: Wed Jul 02, 2008 9:53 am    Post subject: Reply with quote

I don't know C++, but I'm pretty sure you didn't use a namespace..
Back to top
View user's profile Send private message
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Wed Jul 02, 2008 9:58 am    Post subject: Reply with quote

manc wrote:
EDIT: FUCK IT, I'm trying a different tut.
If the old one teaches you to code like that I totally agree with checking out a different tutorial. :P
Back to top
View user's profile Send private message
Caelestis
Expert Cheater
Reputation: 0

Joined: 03 May 2007
Posts: 153

PostPosted: Wed Jul 02, 2008 10:00 am    Post subject: Reply with quote

Want some of my C++ ebooks? I have like 5 gigs of ebooks about computers. About 40 C++ ones.
Back to top
View user's profile Send private message
manc
Grandmaster Cheater
Reputation: 1

Joined: 16 Jun 2006
Posts: 551

PostPosted: Wed Jul 02, 2008 1:11 pm    Post subject: Reply with quote

Caelestis wrote:
Want some of my C++ ebooks? I have like 5 gigs of ebooks about computers. About 40 C++ ones.


Thanks for the offer, but Im going to stick with cplusplus.com for now. Its getting the job done.

And THANK YOU to slovach Very Happy

_________________
Back to top
View user's profile Send private message
MegaForum
Grandmaster Cheater
Reputation: 0

Joined: 20 Aug 2007
Posts: 558

PostPosted: Thu Jul 03, 2008 1:23 pm    Post subject: Reply with quote

Or you can use

Code:

using namespace std;


Much easier imo instead of having to do std : : before all the lines.
Back to top
View user's profile Send private message
Noz3001
I'm a spammer
Reputation: 26

Joined: 29 May 2006
Posts: 6220
Location: /dev/null

PostPosted: Thu Jul 03, 2008 2:07 pm    Post subject: Reply with quote

MegaForum wrote:
Or you can use

Code:

using namespace std;


Much easier imo instead of having to do std : : before all the lines.


He doesn't want to include the whole thing though.
Back to top
View user's profile Send private message MSN Messenger
Typhoon808
Expert Cheater
Reputation: 0

Joined: 27 Mar 2008
Posts: 175
Location: Wales

PostPosted: Thu Jul 03, 2008 3:09 pm    Post subject: Reply with quote

You could either add the std prefix to the code, or just use the certain parts of the namespace, instead of using all of it:

Code:

using std::cout;
using std::endl;


I'm nowhere near great at C++, but if I ever need it for one of my nubby console apps, I would just use the certain sections of the namespace or add the prefix. Razz
Back to top
View user's profile Send private message
lul30
Expert Cheater
Reputation: 0

Joined: 03 Oct 2006
Posts: 197

PostPosted: Sat Jul 05, 2008 7:02 am    Post subject: Reply with quote

Here I did this without a C++ book because I wanna know how far I am at coding in C++ ( just begon 1 day).
Its easy for me because I have C# , java and Vb knowledge.

This is what I came up with:


#include "stdafx.h" // this is my default header of C# (c++)
#include <iostream>
using namespace std; // Using namespace to create room for byte to show a message , if im correct(correct me if im wrong)

int main() // use to be void , void is use to not show or give a message and thats the point of the program so It should be Int

{
//define variables
Int num1;
Int num2;
Int total;
//enter data for the variables
cout << "Enter a value for the first variable: ";
cin >> num1;
cout << "Enter a value for the second variable: "; // Second variable >< it use to said put in first.
cin >> num2;
//add the two numbers together
total = num1 + num2;
//Display the result


cout << "The sum of the numbers = " << total << endl;
return 0; // EVERY int Main() MUST have a return value
}

#working like a charm Smile

#EDIT:: big adjustment to the code WHY are you using floats Evil or Very Mad where working with numbers, so use Int or double if you whant to use whole numbers like 10,12,125,1421341 and not 12,213 and such..
Greetz
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Sat Jul 05, 2008 8:53 am    Post subject: Reply with quote

lul30 wrote:
Here I did this without a C++ book because I wanna know how far I am at coding in C++ ( just begon 1 day).
Its easy for me because I have C# , java and Vb knowledge.


I wouldn't really say much of those but Java help at all with C++.

Quote:
#include "stdafx.h"


You have precompiled headers turned on most-likely or your IDE/compiler creates them for you to assume you will be using them. You can turn it off and avoid having to use these in most if not all compilers.

Quote:
using namespace std; // Using namespace to create room for byte to show a message , if im correct(correct me if im wrong)


Using a namespace simply make you not have to use the namespace prefix for it's members. For example, cin. Without using the namespace like you did, you would have to type:

Code:
std::cin
or
std::cin.whatever();


Including the namespace just makes you avoid having to do that, but it does include the entire namespace which in some opinions is a waste and just creates a lazy coder. I personally dislike using namespaces like this and rather just use the prefixes as the std namespace is rather large and it is highly doubtful you will ever use everything in it in one project.

Quote:
int main() // use to be void , void is use to not show or give a message and thats the point of the program so It should be Int


The main function return is int by standards, some compilers will not accept anything but int, while others will handle any type of return, or most will only accept void or int. But, by 'C' standards the return is int.

Quote:
Int num1;
Int num2;
Int total;


It's int not Int, C is case sensitive.


Just tossing some info out there, not trying to criticize. Smile

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
lul30
Expert Cheater
Reputation: 0

Joined: 03 Oct 2006
Posts: 197

PostPosted: Sat Jul 05, 2008 9:07 am    Post subject: Reply with quote

No no no I really thank you for your comments i like to have someone who corrects me.
It make's me understand that im not qiuet there yet ,and needs to learn more.

And about the "Int" that was just a automatic typing thing to start with a capital. In the source its 'int' ofcourse i know that of java. Like you told me it will help me understand more about c/c++.

wiccaan: Is there a tut out for coding a .dll or something because the point of me learning c++ is making a trainer for maplestory.
Not that I like to hack maplestory but just that i can contribute to a forum.
Or do you want to be my mentor if i dont know what to do? Razz

Thank you very much Wiccaan!
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites