|
-
Sep 13th, 2002, 11:35 PM
#1
Thread Starter
Addicted Member
'string' in function prototype
Hi,
Here is a small portion of code that results in an error message "'string' was not declared in this scope".
Code:
#include <string.h>
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <windows.h>
using namespace std;
bool ReadBitmap(string); //<------------ doesn't like this
int main(int argc, char *argv[])
{
if(ReadBitmap("bg.bmp")==false) return 0; //read file...return if not opened
system("pause");
return 0;
}
Any regular type in the prototype such as char, float, long, etc would be acceptable. But 'strings' aren't well liked. I can do this with 'char' but would like strings since I am a VB dependent programmer. ;-)
So, I imagine there is something 'special' that I must do for this prototype. It probably involves some C++ wierd thing that I am still learning such as... **, (void), ->,*(char*), ., :: :-)
Looking for help.
Regards,
ChuckB
-
Sep 13th, 2002, 11:45 PM
#2
Stuck in the 80s
drop the .h on <string.h>
possibly even for the other ones if that alone doesn't help.
having .h on the end and using namespace std don't go well together.
-
Sep 14th, 2002, 12:05 AM
#3
Thread Starter
Addicted Member
Hobo,
Thanks for responding so quickly. That did it. Thanks!
Regards,
ChuckB
-
Sep 14th, 2002, 12:11 AM
#4
Frenzied Member
Chuck, all of the new standard headers are without the .h. So, you have <vector>, <list>, <iostream>, <string>, <map>, etc, etc. The .h versions are just there for compatability's sake.
Also, if you are just using one or two classes from the std namespace, you can use this syntax:
Code:
#include <vector>
#include <string>
using std::vector;
using std::string;
Doing it this way keeps your global namespace clear.
Z.
-
Sep 14th, 2002, 12:28 AM
#5
Thread Starter
Addicted Member
Hi Z,
Thanks for the tip. I have been studying lots of C/C++ code in the past couple of months and only now is it getting straightened out. I have no idea how I learned to program in the 80's without the internet and forums such as these. :-)
Incidently, I wrote my first 'vector' program tonight demonstrating various uses of vectors and I finally get it. I like the 'dynamic resizing' with push_back(). Really nice.
The code in this thread is helping me to read a bitmap which I will place into a vector instead of an array so I can load my first .bmp textures into my OpenGL stuff.
One last note, do you realize I now have collected three 3" binders full of notes and tutorials I have collected just learning C++? Gotta figure out how to archive this stuff in an easily retrievable manner.
Regards,
ChuckB
-
Sep 14th, 2002, 12:35 AM
#6
Frenzied Member
::taps head:: practice... after a while, it all comes naturally =).
That is a LOT of notes =).
Same thing with this twistiness. At first its just a bunch of gobbldegoop, but after a while, how thing interact start to make sense, and it just opens door after door.
Z.
-
Sep 14th, 2002, 08:02 AM
#7
Monday Morning Lunatic
Originally posted by ChuckB
The code in this thread is helping me to read a bitmap which I will place into a vector instead of an array so I can load my first .bmp textures into my OpenGL stuff.
You're still better off loading it into an array, it's *far* faster, and you shouldn't need the dynamic sizing :-/
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Sep 14th, 2002, 01:13 PM
#8
Thread Starter
Addicted Member
Parksie,
I didn't know arrays were faster then vectors. BUT, I know see the distinction. Let me know if this is correct or not.
If I am loading vertices for a 3D model in which the number of vertices may vary from model to model, I can do two things.
1. Encode the number of vertices in a number at the top of an ASCII/Binary file. Read this number and then create array of that size and load this data into the array.
2. Read the data into vector when I don't know the size using push_back();
For bitmap (.bmp) files, I can read the headers, get the actual size of the bitmap image, so there is no guess work. I simply create an array/vector of that size.
Right?
Regards,
ChuckB
-
Sep 14th, 2002, 01:54 PM
#9
Frenzied Member
Easier and faster to encode the number at the top of the file.
Z.
-
Sep 14th, 2002, 03:37 PM
#10
Monday Morning Lunatic
For the points, use a vector.
For the bitmap, use an array
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|