Loading *.bmp
New at C++. I am trying to load a number of bitmaps within a for loop and this code returns an error of error C2110: ''+'' : cannot add two pointers. Trying to load pic1, pic2, ect and using the variable ''i'' as a counter. Any ideas
char *strPath = "Data/pic" + i + ".bmp";
Thanks in advance,
Dave
August 25, 2003 10:23 PM
Hey man, this aint no java app here. You gotta use strcat and strcpy, ie
strcat(destination, source);
so, in your case:
char* strPath;
char* tmp;
strcpy(strPath, "Data/pic"
;
sprintf(tmp, "%d.bmp", i);
strcat(strPath, tmp);
Is there anyone with a better implementation?
strcat(destination, source);
so, in your case:
char* strPath;
char* tmp;
strcpy(strPath, "Data/pic"

sprintf(tmp, "%d.bmp", i);
strcat(strPath, tmp);
Is there anyone with a better implementation?
I had the same experience when i moved from java to c++.
But C++ does support strings.
#include <string>
using namespace std;
string path;
path = "Data/pic" + i + ".bmp";
Exactly the same as in java,only u need to import it. And the string is not string.h, just string.
When u pass it in though, your function might require old style C strings. In this case just do this.
LoadBMP(path.c_str());//presuming LoadBMP is your function for loading the BMP
But C++ does support strings.
#include <string>
using namespace std;
string path;
path = "Data/pic" + i + ".bmp";
Exactly the same as in java,only u need to import it. And the string is not string.h, just string.
When u pass it in though, your function might require old style C strings. In this case just do this.
LoadBMP(path.c_str());//presuming LoadBMP is your function for loading the BMP
Hi Everybody:
Thanks for the info! I am still getting errors though. I am using Visual C++ as a compiler.
Anonymous Poster compilers ok but gets stuck "Access violation in strcat.asm.
GamerSg gives me the same error I was having.
Code again
...
...
AUX_RGBImageRec *LoadBMP(char *Filename) // Function header...
...
...
for ( i=0; i<5; i++){
char* strPath=""; // Hade to set to "" to compile
char* tmp="";
strcpy(strPath,"Data/pic");
sprintf(tmp, "%d.bmp", i);
strcat(strPath, tmp);
if (TextureImage=LoadBMP(strPath)){
...
Any ideas?
Thanks for the info! I am still getting errors though. I am using Visual C++ as a compiler.
Anonymous Poster compilers ok but gets stuck "Access violation in strcat.asm.
GamerSg gives me the same error I was having.
Code again
...
...
AUX_RGBImageRec *LoadBMP(char *Filename) // Function header...
...
...
for ( i=0; i<5; i++){
char* strPath=""; // Hade to set to "" to compile
char* tmp="";
strcpy(strPath,"Data/pic");
sprintf(tmp, "%d.bmp", i);
strcat(strPath, tmp);
if (TextureImage=LoadBMP(strPath)){
...
Any ideas?
quote:
Original post by dsteere
Hi Everybody:
Anonymous Poster compilers ok but gets stuck "Access violation in strcat.asm.
char* strPath=""; // Hade to set to "" to compile
char* tmp="";
Any ideas?
Hi
You was close with idea char* strPath="" but try this way
char strPath[256];
char tmp[256];
[Edit:]
this way will be the best
char tmp[MAX_PATH];
sprintf(tmp, "Data/pic%d.bmp", i);
or
char Path[MAX_PATH];
char *basePath = "Data/pic";
char *fileExt = "bmp";
sprintf(Path, "%s%d.%s", basePath, i, fileExt);
"The Gods Made Heavy Metal And They Saw That It Was Good
They Said To Play It Louder Than Hell We Promised That We Would
When Losers Say Its Over With You Know That It’s A Lie
The Gods Made Heavy Metal And It’s Never Gonna Die"
THE GODS MADE HEAVY METAL/by ManOwaR
[edited by - Estor on August 26, 2003 2:20:39 AM]
"The Gods Made Heavy Metal And They Saw That It Was Good They Said To Play It Louder Than Hell We Promised That We WouldWhen Losers Say Its Over With You Know That It's A Lie The Gods Made Heavy Metal And It's Never Gonna Die"THE GODS MADE HEAVY METAL/by ManOwaR
Oops i think i made a tiny mistake.
The + can only be used to join strings.
So you can try this instead.
#include <string>
using namespace std;
string path;
sprintf(path,"Data/pic%d.bmp",i);
The + can only be used to join strings.
So you can try this instead.
#include <string>
using namespace std;
string path;
sprintf(path,"Data/pic%d.bmp",i);
quote:
Original post by GamerSg
#include <cstring>
"Literally, it means that Bob is everything you can think of, but not dead; i.e., Bob is a purple-spotted, yellow-striped bumblebee/dragon/pterodactyl hybrid with a voracious addiction to Twix candy bars, but not dead."- kSquared
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement