Code:
#ifndef CANDIES_H
#define CANDIES_H
#include <iostream>
#include <fstream>
#include <Global.h>
class Candies
{
public:
void getName(std::string name, int i);
void getPosition(std::string position, int i);
void getClass(std::string Class, int i);
void getImageFile(std::string file, int i);
std::string loadName(int i);
void loadPosition(int i);
void loadClass(int i);
void loadImageFile(int i);
protected:
private:
std::string name[15];
std::string position[15];
std::string Class[15];
std::string file[15];
std::string name_addTXT[15];
std::string position_addTXT[15];
std::string Class_addTXT[15];
std::string file_addTXT[15];
std::string temp;
};
#endif // CANDIES_H
Code:
#include "Candies.h"
#include <Windows.h>
#include <iostream>
#include <fstream>
#include <sstream>
#include <Global.h>
using namespace std;
void Candies::getName(std::string name, int i)
{
name_addTXT[i] = name;
name_addTXT[i] += ".txt";
ofstream nameTXT;
nameTXT.open(name_addTXT[i].c_str());
nameTXT << name << std::endl;
nameTXT.close();
}
void Candies::getPosition(std::string position, int i)
{
position_addTXT[i] = position;
position_addTXT[i] += ".txt";
ofstream positionTXT;
positionTXT.open(position_addTXT[i].c_str());
positionTXT << position << std::endl;
positionTXT.close();
}
void Candies::getClass(std::string Class, int i)
{
Class_addTXT[i] = Class;
Class_addTXT[i] += ".txt";
ofstream classTXT;
classTXT.open(Class_addTXT[i].c_str());
classTXT << Class << std::endl;
classTXT.close();
}
void Candies::getImageFile(std::string file, int i)
{
file_addTXT[i] = file;
file_addTXT[i] += ".txt";
ofstream fileTXT;
fileTXT.open(file_addTXT[i].c_str());
fileTXT << file << std::endl;
fileTXT.close();
}
std::string Candies::loadName(int i)
{
ifstream file;
file.open(name_addTXT[i].c_str());
file >> name[i];
temp = name[i];
file.close();
return temp;
}
When I tested it, the file name in getName() outputted the right file name. However the file name in loadName() does not print out anything in the console window.
Can anyone explain to me why, and the best solution for this? I want it to be so that the strings in [I]name_addTXT.c_str() in both functions are equal.
Thanks.