0
我想從txt文件輸入數據。 該文件包含二維數組[5] [5] 如何打印出我想要的任何值? 我不希望打印出整個5點* 5的數據我想從二維數組打印出一些值C++
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
double distance[5][5] ;
string line;
ifstream ratefile;
ratefile.open("a.txt");
ofstream file;
if (ratefile.is_open())
{
while (! ratefile.eof())
{
getline (ratefile,line);
ratefile.getline(distance, 25, '*');
cout << "\nDistance [0][0]" << ": " << distance[0][0];
cout << "\nDistance [0][1]" << ": " << distance[0][1];
cout << "\nDistance [0][2]" << ": " << distance[0][2];
cout << "\nDistance [0][3]" << ": " << distance[0][3];
cout << "\nDistance [1][0]" << ": " << distance[1][0];
cout << "\nDistance [1][1]" << ": " << distance[1][1];
cout << "\nDistance [1][2]" << ": " << distance[1][2];
cout << "\nDistance [1][3]" << ": " << distance[1][3];
cout << endl;
cin.get();
return 0;
}
你錯過一些線路中的碼? – Fox32 2011-03-02 13:11:30
作爲一名程序員,如果我想打印出我想要的值,我會打印出我想要的值。如果你想有人回答這個問題,你需要指定問題是什麼...... – Lindydancer 2011-03-02 13:12:40
這是家庭作業嗎? – Nav 2011-03-02 13:25:57