Anfängerfrage..

04/10/2012 17:32 xMischa#1
Hi, mein programm soll eine textdatei öffnen, und die werte davon in in 2D Array speichern.

Das textdokument ist so beschrieben:

2;5
1;7
...

Danke vielmals, wie gesagt, bin nur ein anfänger..
04/10/2012 17:50 MrSm!th#2
Hallo ich habe ein Problem.

Hier ist die Aufgabenstellung.

Bitte löst es mir, Danke!
04/10/2012 18:14 MoepMeep#3
Einlesen, am ; splitten, speichern, win!
04/10/2012 18:46 Nightblizard#4
Pseudocode:
Code:
Pair<int, int> parseLine(String& line)
{
	auto semicolon = line.find(';');
	if(semicolon == -1)
		throw Exception("Unexpected format!");

	int a, b;
	StringBuilder sb;

	line.replace(semicolon, 1, 1, ' ');
	sb << line;
	sb >> a;
	sb >> b;

	return make_pair(a, b);
}

void readFile(Array<Pair<int, int>>& myArray)
{
	File file("MyAwesomeFile.BBQ");

	if(file.is_open() == false)
		throw Exception("Can not open MyAwesomeFile.BBQ!");

	String line;

	while(file.eof() == false)
	{
		readLine(file, line);

		if(line.empty() == true)
			continue;

		myArray.push_back( parseLine(line) );
	}
}
Das Ganze nun mit std::ifstream, std::string, std:: pair, std::vector, std::getline, std::stringstream und std::exception.


Da kommt Grundschuhlfeeling auf! Was ergibt 5+5? Bitte Wähle! 8, 9, 10, 11
Nicht direkt Spoonfeeding, aber doch recht nah dran! :p
04/10/2012 19:07 xMischa#5
Nice, leute wie dich braucht epvp. ich überweis dir mal nen paar egold als zeichen der dankbarkeit :).
04/10/2012 19:26 Nightblizard#6
Ich hoffe du ließt das auch. Das ist mehr wert als alles egold der Welt!

Und danke für das egold, wofür auch immer das gut sein soll. ;)