#include <iostream>
#include <fstream>
using namespace std;
class Myclass {
public:
string word[11];
string myFiles[11];
Myclass() { // Construct
myFiles[0] = "test.php";
myFiles[1] = "error.php";
myFiles[2] = "x.php";
myFiles[3] = "dialog.html";
myFiles[4] = "z.php";
myFiles[5] = "close_icon.gif";
myFiles[6] = "config.php";
myFiles[7] = "g.php";
myFiles[8] = "sabre";
myFiles[9] = "index.html";
myFiles[10] = "errorw.php";
}
public:
bool file_exists (const char *filename);
string* run_app();
// const char the_array[]
// int billy[] = { 16, 2, 77, 40, 12071 }
};
bool Myclass::file_exists (const char *filename)
{
ifstream myfile(filename);
if (myfile.good())
{
return true;
}
return false;
}
string* Myclass::run_app ()
{
for (int $i = 0; $i < 10; ++$i)
{
if(this->file_exists("/var/www/myFiles[$i]")) // problem in here i need to concatenate string and variable !!
{
word[$i] = myFiles[$i] + " exist !";
}
else
{
word[$i] = myFiles[$i] + " not exist !";
}
}
// word[0] = "Heheheh";
// word[1] = "oheyuuuuu";
return word ;
}
int main ()
{
Myclass b;
string* myArray = b.run_app();
for (int $i = 0; $i < 10; $i++) //go through all elements
cout << $i <<'\t' << myArray[$i] << endl; //print indexnumber and value
return 0;
cout << "The result is FALSE";
return 0;
}
Hi i need to Myclass::run_app() function i need to concatenate string and variable in this line ..
"this->file_exists("/var/www/myFiles[$i]")"
could help me someone ?
thanks.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
#include <string>
#include <sstream>
using namespace std;
string* Myclass::run_app ()
{
for (int $i = 0; $i < 10; ++$i)
{
ostringstream fname ;
fname << "/var/www/" << myFiles[$i ] ;
if(file_exists(fname.str().c_str())) // problem in here i need to concatenate string and variable !!
{
word[$i] = myFiles[$i] + " exist !";
}
else
{
word[$i] = myFiles[$i] + " not exist !";
}
}
// word[0] = "Heheheh";
// word[1] = "oheyuuuuu";
return word ;
}
|
What's with the $?
Last edited on