Hier ist der Code, den ich bisher habe.C++ Lesen von einer Textdatei in ein Array/String
Was muss ich aus zwei verschiedenen Textdateien, Matrix A und Matrix B tun lesen
ich dies jedoch für jede Textdatei Matrix tun kann ich es nur mit
1 0 0
aufkommt lesen
(also im Grunde die erste Zeile), wo die ganze Textdatei für Matrix A in der Tat ist
1 0 0
2 0 0
3 0 0
so weiß es jemand, wie ich das tun kann?
Danke!
#include <iostream> //declaring variables
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;
string code(string& line);
int main()
{
ofstream outf;
ifstream myfile;
string infile;
string line;
string outfile;
cout << "Please enter an input file (A.txt) for Matrix A or (B.txt) for Matrix B" << endl;
cin >> infile; //prompts user for input file
if (infile == "A.txt")
{ //read whats in it and write to screen
myfile.open("A.txt");
cout << endl;
getline (myfile, line);
cout << line << endl;
}
else
if (infile == "B.txt")
{
myfile.open("B.txt");
cout << endl;
getline (myfile, line);
cout << line << endl;
}
else
{
cout << "Unable to open file." << endl;
}
//{
//while("Choose next operation");
//}
return 0;
}
eine Schleife verwenden, vielleicht? –