かなり近い部分まで来ていると思うのですが、上手く動作させることが出来ません。
それっぽい数値がとれているのですがずれてしまうのと、
vector型に代入する時にピラミッドみたいな形になってしまします。
サイズの取得は出来たのですが、whileで回してる部分がおかしいのですが、どうしても直すことが出来ません。
宜しければで構いませんのでアドバイスを頂けないでしょうか・・・。
■参考サイト
http://scitex.hateblo.jp/entry/2013/02/23/231640
■map_01.csv
※最初の1行目はCSVのサイズを指定しております。2行目からCSVとして格納したいです。
Map[5][3]
0,1,2,3,4
10,11,12,13,14
20,21,22,23,24
■読み込みクラス
#include <iostream>
#include <fstream>
#include <ostream>
#include <string>
#include <vector>
class MAP_SET{
public:
unsigned int MAP_X;
unsigned int MAP_Y;
std::vector< std::vector<int> > values;
void LoadMapCSV( const char* filename );
};
void MAP_SET::LoadMapCSV( const char* filename ){
NSString* data = [NSString stringWithCString:filename encoding:NSUTF8StringEncoding];
NSString* path = [[NSBundle mainBundle] pathForResource:data ofType:nil];
const char* mainfest_path = [path fileSystemRepresentation];
std::fstream ifs;
ifs.open( mainfest_path, std::fstream::in );
if ( !ifs.is_open() ) {
return;
}
std::string is_data;
bool x_y = false;
// サイズを取得
while ( is_data != "\n" ) {
is_data = ifs.get();
if( is_data == "[" ){
std::string numdata;
while ( !ifs.eof() ) {
is_data = ifs.get();
if(is_data == "]"){
break;
}
numdata += is_data;
}
if( !x_y ){
this->MAP_X = (unsigned int)atoi( numdata.c_str() );
x_y = true;
}else{
this->MAP_Y = (unsigned int)atoi( numdata.c_str() );
}
}
}
std::string numdata;
int p;
printf( "%d %d", this->MAP_X, this->MAP_Y );
while( getline(ifs, numdata) ){
if( ( p = numdata.find("//")) != numdata.npos ) continue;
std::vector<int> inner;
while( (p = numdata.find(",")) != numdata.npos ){
//printf( "%s,", numdata.substr(0, p).c_str() );
numdata = numdata.substr(p+2);
inner.push_back((int)atoi(numdata.substr(0, p).c_str()));
this->values.push_back( inner );
}
//printf( "\n" );
}
for( unsigned int y = 0; y < values.size(); y++ ){
for( unsigned int x = 0; x < values[y].size(); x++ ){
printf( "%d,", this->values[y][x] );
}
printf( "\n" );
}
ifs.close();
}
//// 出力結果
0,
0,0,
0,0,0,
0,0,0,0,
1,
1,2,
1,2,3,
1,2,3,4,
1,
1,2,
1,2,3,
1,2,3,4,