Author Topic: C++ Help.  (Read 1932 times)

0 Members and 1 Guest are viewing this topic.

What compiler are you using?  It should be telling you these things.

 

Offline PeachE

  • Artisté
  • 26
    • http://www.cs.trinity.edu/~dwhite/main.html
on iniparse:

for one thing, it looks like you're using some version of visual studio, so stop using ".h" on iostream and fstream. stop it now!

second, on your iniparse.cpp you define a constructor for ini that takes a character array. delete the word "void". constructors do not have a return type. you also need to close your ini class. so at the bottom of iniparse.h, right before #endif, add  "};"

another thing you need to do is identify the namespace of cout. unless you want to write "std::cout" everytime, i suggest at the top of the files that use this function, right under the includes, type "using namespace std;"

also, in your main function, both of your input parameters are named argv. name one of them argc (there's a convention for this - i think it's the first one but i'm not sure).

one last thing. you're defining OutMessage after you use it (same with the const SendLevel) and you're defining it twice. you'll never need two definitions unless you overload, but  a good tip is to put all your helper functions and global consts in a seperate header file(s) and then include that when you need them.


if you are using Visual studio, and you make all these changes you'll still get an error along the lines of: iniparse.obj already contains an instance of OutMessage..blah... if you do, it's because VS is trying to be friendly. VS tries to automatically do the work of a makefile and i believe links all the files in the same namespace for you, so you don't need the usual #include "iniparse.h". (don't take my word on this one though - it's been a while since i've done c++ - i've got c# on the brain this week)
« Last Edit: August 01, 2004, 11:21:20 pm by 136 »

 

Offline PeachE

  • Artisté
  • 26
    • http://www.cs.trinity.edu/~dwhite/main.html
oh, and i've got work tomorrow, so i don't have time to go through the whole thing right now. but i'll try to check it out later this week and see what's up.

 

Offline Kosh

  • A year behind what's funny
  • 210
C++ compilers have a tendency to be a bit....twitchy. Sometimes they will give you out of memory errors even though there is plenty of free system memory.
"The reason for this is that the original Fortran got so convoluted and extensive (10's of millions of lines of code) that no-one can actually figure out how it works, there's a massive project going on to decode the original Fortran and write a more modern system, but until then, the UK communication network is actually relying heavily on 35 year old Fortran that nobody understands." - Flipside

Brain I/O error
Replace and press any key

 
Yeah, I'm using VC6.

When I remove the H I get an error.

Why the namespace thingy, everything works now, right?

I overloaded the message thingy on purpose, and I put it in a seperate file by now.

I'll re-upload, but everything works now, thanks to some help from Kazan and you guys.
just another newbie without any modding, FREDding or real programming experience

you haven't learned masochism until you've tried to read a Microsoft help file.  -- Goober5000
I've got 2 drug-addict syblings and one alcoholic whore. And I'm a ****ing sociopath --an0n
You cannot defeat Windows through strength alone. Only patience, a lot of good luck, and a sledgehammer will do the job. --StratComm

 

Offline PeachE

  • Artisté
  • 26
    • http://www.cs.trinity.edu/~dwhite/main.html
Quote
Originally posted by kasperl
When I remove the H I get an error


hmm.. might just be a dotNet thing. dunno. like i said, been a while since i've done c++

Quote
Why the namespace thingy, everything works now, right?


the way it is now, it won't work on every compiler. when i compiled it, i got errors like "cout not found". if you add the using namespace line, it will prevent this.

Quote
I overloaded the message thingy on purpose, and I put it in a seperate file by now.


ah, i didn't notice that one took an int and one took a character pointer. coo' but yeah, they should still go in another file.

 

Offline FreeTerran

  • Master of the apocalypse
    Reset count: 1
  • 210
well i had a c++ problem too i try to learn it :)

but if i compile the code i get some weird errors

Code: [Select]
#include

int main ()
{
  cout << "Hello World! ";
  cout << "I'm a C++ program";
  return 0;
}


i'm using vc++ 6.0 and this tutorial http://www.cplusplus.com/doc/tutorial/tut1-1.html

errors:
Code: [Select]
D:\Programme\cpp-dev\projects\main.c(7) : error C2065: 'cout' : undeclared identifier
D:\Programme\cpp-dev\projects\main.c(7) : error C2297: '<<' : illegal, right operand has type 'char [14]'
D:\Programme\cpp-dev\projects\main.c(8) : error C2297: '<<' : illegal, right operand has type 'char [18]'


i hope someone could help me :nervous:
Silva in lumine Lunae arcana est. Domos mea Silva in lumine Stellarum est.

 

Offline aldo_14

  • Gunnery Control
  • 213
Shouldn't you have something next to that #include?  

EDIT need #include [iostream.h] (with < brackets instead of square) - that defines the standard, IIRC, C++ IO library for sending output messages to the screen (etc).  (that's also why it doesn't recognise cout, that'll be defined in iostream)
« Last Edit: August 02, 2004, 11:28:03 am by 181 »

 

Offline FreeTerran

  • Master of the apocalypse
    Reset count: 1
  • 210
mhh they dosen't copy it into the post but its in the source ;)

#include < iostream.h >

without the spaces^^
Silva in lumine Lunae arcana est. Domos mea Silva in lumine Stellarum est.

 

Offline aldo_14

  • Gunnery Control
  • 213
I presume you've got your classpaths (Java term, not sure if it's different for C++) setup so it can find the iostream.h file?  (i.e. have you got the previous  code to work)

 

Offline FreeTerran

  • Master of the apocalypse
    Reset count: 1
  • 210
I check that the directory where iostream.h is located is included in vc++ 6.0 :(
Silva in lumine Lunae arcana est. Domos mea Silva in lumine Stellarum est.

 

Offline PeachE

  • Artisté
  • 26
    • http://www.cs.trinity.edu/~dwhite/main.html
try this instead

Code: [Select]
#include < iostream >
using namespace std;

 

Offline FreeTerran

  • Master of the apocalypse
    Reset count: 1
  • 210
ok i found the error filename was main.c but must be a c++ file so .cpp :)
« Last Edit: August 02, 2004, 12:11:12 pm by 1059 »
Silva in lumine Lunae arcana est. Domos mea Silva in lumine Stellarum est.

  

Offline milo

  • 21
    • http://www.starshatter.com
Quote
Originally posted by WMCoolmon
When you're checking for a null pointer, if(pFirst == 0) should be if(pFilrst == NULL), it is considered bad practice to assume null pointers are 0; although they are on Win32 and Linux, I believe.

Actually, the standard says that null pointers must be integral constants that evaluate to zero, even if the underlying physical representation of the pointer does not have all bits set to zero.  It is perfectly safe to use if (pFirst == 0) or even if (!pFirst) in any C++ program.  

Of course, individual programming teams may choose to use other syntax as a matter of personal preference.