Kod: Zaznacz cały
2
12 12 12 12
12 12 12 12
12 12 12 12
12 12 12 12
Kod: Zaznacz cały
#include<iostream>
#include<fstream>
#include<string>
#include<sstream>
using namespace std;
int main(int argc, char *argv[]){
ifstream dane_we;
string calosc="",znak;
string tab[4][4];
int i=0,j=0;
int licz=0;
dane_we.open(argv[1],ios::in);
while(dane_we.good()){
znak=dane_we.get();
if(znak!="\n"){
if(znak==" "){
tab[i][j]=calosc;
j++;
calosc="";
}else{
calosc+=znak;
}
}else{
tab[i][j]=calosc;
i++;
j=0;
calosc="";
}
}
for(i=0;i<4;i++)
for(j=0;j<4;j++)
cout<<"tab["<<i<<"]["<<j<<"]="<<tab[i][j]<<endl;
dane_we.close();
return 0;
}
Ktos wie, jak wczytac pierwsza liczbe (u mnie np. 2 ) do zmiennej, a nastepne juz do tablicy o rozmiarze n^2xn^2 ? I jeszcze skonwertowac to na int, zeby tablica byla int** tab, a nie string tab ..
EDIT:
Kod: Zaznacz cały
#include<iostream>
#include<fstream>
#include<string>
#include<sstream>
using namespace std;
int main(int argc, char *argv[]){
ifstream dane_we;
int n,rozmiar;
dane_we.open(argv[1],ios::in);
dane_we>>n;
rozmiar=n*n;
cout<<"Rozmiar:"<<rozmiar<<endl;
int** tab;
tab = new int*[rozmiar];
for(int i=0;i<rozmiar;i++)
tab[i] = new int[rozmiar];
int k=0;
while(dane_we)
dane_we>>tab[k++][k++];
for(int i=0;i<rozmiar;i++){
for(int j=0;j<rozmiar;j++){
cout<<tab[i][j]<<" ";
if(j==rozmiar-1)
cout<<"\n";
}
}
dane_we.close();
system("Pause");
return 0;
}
