私はこの問題に関してあなたの助けをすることができました。私はこれを含むファイルを持っています:getlineを使ってファイルから配列を読み込む方法
1x+1y+1z=5
2x+3y+5z=8
4x+0y+5z=2
私はそれを文字列に保存する必要があります。格納されると、出力は次のようになります。
1x+1y+1z=5
a=1 b=1 c=1 d=5
2x+3y+5z=8
a=2 b=3 c=5 d=8
4x+0y+5z=2
a=4 b=0 c=5 d=2
これは私が持っているコードですが、何も出力されません。誰か助けてくれますか? 19行目にエラーが表示されますが、それを修正する方法はわかりません。エラーは、「呼び出しに一致する機能がありません」と表示されます。
|19|error: no matching function for call to 'std::basic_ifstream::getline(std::string [10], int)'| |22|error: no matching function for call to 'std::basic_istringstream::basic_istringstream(std::string [10])'|
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
using namespace std;
int main()
{
ifstream file("matrix.txt");
if (!file)
{
cout << "Could not open input file\n";
return 1;
}
for (string line[10]; file.getline(line, 10);)
{
cout << line << '\n';
istringstream ss(line);
double a, b, c, d;
char x, y, z, eq;
if (ss >> a >> x >> b >> y >> c >> z >> eq >> d)
{
if (x == 'x' && y == 'y' && z == 'z' && eq == '=')
{
cout << "a = " << a
<< " b = " << b
<< " c = " << c
<< " d = " << d << '\n';
}
else
{
cout << "parse error 2\n";
}
}
else
{
cout << "parse error 1\n";
}
}
}
「なぜ、このコードの動作はしません」 – Tyler
を実行している/コンパイルするときあなたが得るすべてのエラーを提供してください尋ねるたびに[ 'std名前空間を使用して;'悪い習慣です]( https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice)、絶対に使用しないでください。 – tambre
'for(string line [10]; file.getline(line、10);)'この行は、私にとって非常に疑わしいです。 – Borgleader