Valhalla Legends Archive

Programming => General Programming => C/C++ Programming => Topic started by: ChroniX on January 16, 2007, 11:14 PM

Title: Header Symbol
Post by: ChroniX on January 16, 2007, 11:14 PM
Hello, I recently took up learning C++ in preparation for future game development (And sure do have plenty of time to learn since I don't attend school or have a job). I ran into something I'm not sure of that I am hoping somebody here could answer for me.

Does the # symbol in the header for "#include" stand as a sharp or a number? I assume sharp at the moment, but will revoke my thoughts until I get a correct answer.

Thanks,
   Brian
Title: Re: Header Symbol
Post by: UserLoser on January 17, 2007, 12:14 AM
it's a precompiled header or directive.  tells the compiler to do something before compiling the code.  in this case, including a file full of probably definitions
Title: Re: Header Symbol
Post by: warz on January 17, 2007, 01:33 AM
they're called preprocessor directives, here's a quality hyper link: http://www.cplusplus.com/doc/tutorial/preprocessor.html
Title: Re: Header Symbol
Post by: shout on January 18, 2007, 02:11 PM
I might be a little off, but I think what you are asking is if the symbols used in C++ (like #, *, ->, ect.) have any ties to what the symbols would mean  if you were not using a programming langauge... I think.

The answer to that would be no. The '#' is just a non-alphanumeric symbol that happens to be used in pre-compiler directives. Some math symbols (+, -, ect) are common sense, adding by using the tilde would be confusing.

I think thats what you were asking... I'm not sure though...
Title: Re: Header Symbol
Post by: ChroniX on January 18, 2007, 03:29 PM
Sounds right on target to me!  ;)

I just never knew as to whether or not the symbol had any sort of name associated with it.

C++ is a great language to learn. I'm sure my time spent learning it will be well worth it. I know that Battle.net's population is slowly coming to an end, but I want to eventually write a bot for channel moderation.
Title: Re: Header Symbol
Post by: ChroniX on January 18, 2007, 03:34 PM
Also, I have heard you can only use the cout function when using <iostream>. Is this true?
Title: Re: Header Symbol
Post by: DeTaiLs on January 18, 2007, 03:48 PM
Yes it is true, read this it tells you some of the functions for each libary
http://www.cplusplus.com/reference/iostream/
Title: Re: Header Symbol
Post by: MyndFyre on January 18, 2007, 04:15 PM
Quote from: ChroniX on January 18, 2007, 03:34 PM
Also, I have heard you can only use the cout function when using <iostream>. Is this true?

cout isn't actually a function, it's an object.
Title: Re: Header Symbol
Post by: ChroniX on January 18, 2007, 05:30 PM
Well Mynd, thank you very much for pointing that out.  :P
Title: Re: Header Symbol
Post by: ChroniX on January 18, 2007, 07:21 PM
Well I'm having a problem here and hopefully somebody can help me. I get this error when trying to compile the code below

error C2784: 'std::basic_istream<_Elem,_Traits> & (Location of project on drive)

#include <iostream>

using namespace std;

int main()
{
int number;

cout<<"Please enter a number: ";
cout>> number;
cin.ignore();
cout<<"You entered: "<< number <<"\n";
cin.get();
}
Title: Re: Header Symbol
Post by: K on January 18, 2007, 07:38 PM

cout >> numer;


you can't get input from cout.


cin >> number;
Title: Re: Header Symbol
Post by: ChroniX on January 18, 2007, 07:49 PM
Ah okay, that's it! Thank you very much for your help.  :)
Title: Re: Header Symbol
Post by: ChroniX on January 20, 2007, 07:54 AM
What is wrong with this code? It will compile but wont execute.

#include <iostream>

using namespace std;

void playgame();
void loadgame();
void playmultiplayer();

int main()
{
  int input;
 
  cout<<"1. Play game\n";
  cout<<"2. Load game\n";
  cout<<"3. Play multiplayer\n";
  cout<<"4. Exit\n";
  cout<<"Selection: ";
  cin>> input;
  switch ( input ) {
  case 1:
    playgame();
    break;
  case 2:
    loadgame();
    break;
  case 3:
    playmultiplayer();
    break;
  case 4:
    cout<<"Thank you for playing!\n";
    break;
  default:
    cout<<"Error, bad input, quitting\n";
    break;
  }
  cin.get();
}
Title: Re: Header Symbol
Post by: Warrior on January 20, 2007, 11:48 AM
Why don't you use a little debugging (either with breakpoints in VS or simply by printing out the value of input)