Original Post
🔒 Locked
type convertion problem
Advertisement
In C, I'd use sprintf.
P.S. Using snprintf() is probably safer because it passes the size of the buffer to the function as well. This prevents buffer overruns.
2nd P.S Since you said you're coding in C++ ...
char myBuffer[ 200 ] = { 0 };for ( int myInt = 1; myInt <= 128; ++myInt ){ sprintf( myBuffer, "%i.pgm", myInt ); // Do something with the name that you just wrote to myBuffer. // ...}P.S. Using snprintf() is probably safer because it passes the size of the buffer to the function as well. This prevents buffer overruns.
2nd P.S Since you said you're coding in C++ ...
#include <sstream>void func(){ for ( int i = 1; i <= 128; ++i ) { std::ostringstream myStream; myStream << i << ".pgm"; // Call myStream.str() to get the string. }}
Hi again, am still getting some troubles
void func()
{
for ( int i = 1; i <= 128; ++i )
{
std::ostringstream myStream;
myStream <<"images/"<< i << ".pgm";
}
}
when am displaying it through cout<
ifstream indata;
indata.open(myStream.str());
i could have stored it in a string first like
char temp[10];
strcpy(temp,myStream.str());
but its unable to copy the string(probably because its not a string) into temp;but i need to use it with indata.open()
Any other alternatives?
void func()
{
for ( int i = 1; i <= 128; ++i )
{
std::ostringstream myStream;
myStream <<"images/"<< i << ".pgm";
}
}
when am displaying it through cout<
ifstream indata;
indata.open(myStream.str());
i could have stored it in a string first like
char temp[10];
strcpy(temp,myStream.str());
but its unable to copy the string(probably because its not a string) into temp;but i need to use it with indata.open()
Any other alternatives?
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement