Well, this project I'm working on is a Pokedex Program for my little sister for her birthday.

Anyways, I have a file PokeList.txt, which I want to store every Pokemon next to their ID number.

The text file is:

1. Bulbasaur
2. Ivysaur
3. Venusaur
4. Charmander
5. Charmeleon
6. Charizard

The script is:

std::string Pokemon::ListPokemon() {
	std::ifstream file;

	std::string filename = "PokeList.txt";
	file.open(filename.c_str());

	if(!file.is_open()) {
		return "An error occured while trying to open PokeList.txt, file reading failed...\n";	
	}

	while(!file.eof()) {
	}

	file.close();
}

I need it to put each line in an array from the text file. So basicly it will put them in the array like:

array("1. Bulbasaur", "2. Ivysaur") etc...

Help please, thanks ;)

Well, this project I'm working on is a Pokedex Program for my little sister for her birthday.

Awww, so sweet. I used to love Pokemon. All 507 of them (not really all).

std::string line;
while(std::getline(file,line))
{
   //Here you go.
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.