新しい順のリスト取得

このQ&Aのポイント
  • 特定の回答者のおかげで収束につながりました。新しい順にソートする機能を追加したいです。
  • ファイルの古い順にリストを作成してもらいましたが、新しい順にソートする機能が必要です。
  • ファイルのリストを新しい順にソートする機能を追加したいです。
回答を見る
  • ベストアンサー

新しい順のリスト取得

この件につきましては、特定の回答者の方のおかげで収束につながりました。あとひとつだけお力をください。ファイルの古い順にリストを作成してもらいましたが、これに新しい順にソートする機能を追加したいです。これで仕様としては終わりです。どうかよろしくお願いいたします bool operator<(const FILETIME& x, const FILETIME& y) { if ( x.dwHighDateTime < y.dwHighDateTime ) return true; if ( y.dwHighDateTime < x.dwHighDateTime ) return false; return x.dwLowDateTime < y.dwLowDateTime; } class DML_Backup { public: vector<string> files_; void search(const char* spec) { typedef multimap<FILETIME,string> map_type; map_type files; WIN32_FIND_DATAA find_data; HANDLE handle = FindFirstFileA(spec, &find_data); if ( handle != INVALID_HANDLE_VALUE) { do { files.insert(map_type::value_type(find_data.ftLastWriteTime, find_data.cFileName)); } while ( FindNextFileA( handle, &find_data) ); FindClose(handle); } files_.clear(); for ( map_type::iterator iter = files.begin(); iter != files.end(); ++iter ) { files_.push_back(iter->second);         } }

質問者が選んだベストアンサー

  • ベストアンサー
回答No.1

もっとも簡単なのは"古い順に並べた後反転↓する"。 reverse(filres.begin(), filesn.end());

その他の回答 (1)

回答No.2

// timeOrder … TRUE:新しい日付順にソート、FALSE:古い日付順にソート void DML_Backup::search(const char* spec, bool timeOrder) {   …(省略)…   files_.clear();   for ( map_type::iterator iter = files.begin(); iter != files.end(); ++iter ) {     if( timeOrder ) files_.push_back(iter->second);     else files_.insert(files_.begin(), iter->second);   } }

babel05177
質問者

お礼

ありがとうございました。今回の件は何とかなりました。

関連するQ&A

  • ファイル名リストの置換処理

    以前、ファイルリストの取得について教えて頂きました。ありがとうございます。 取得したリストを文字列で入れ替えるにはどうすればよいでしょうか 例えば取得したリストの最初の位置の文字列dml[0]をEcoDataFileNameと置き換えたいです。 #include <Windows.h> #include <map> #include <vector> #include <string> #include <iostream> #include "time.h" using namespace std; bool operator<(const FILETIME& x, const FILETIME& y) { if ( x.dwHighDateTime < y.dwHighDateTime ) return true; if ( y.dwHighDateTime < x.dwHighDateTime ) return false; return x.dwLowDateTime < y.dwLowDateTime; } class DML_Backup { vector<string> files_; public: void search(const char* spec) { typedef multimap<FILETIME,string> map_type; map_type files; WIN32_FIND_DATAA find_data; HANDLE handle = FindFirstFileA(spec, &find_data); if ( handle != INVALID_HANDLE_VALUE) { do {   files.insert(map_type::value_type(find_data.ftLastWriteTime, find_data.cFileName)); } while ( FindNextFileA( handle, &find_data) ); FindClose(handle); } files_.clear(); for ( map_type::iterator iter = files.begin(); iter != files.end(); ++iter ) { files_.push_back(iter->second); } } string operator[](int inx) const { return files_.at(inx).c_str(); } int size() const { return files_.size(); } }; int main() { DML_Backup dml; char EcoDataFileName="MonJun131956122011.ecd"; dml.search("*.ecd"); }

  • 文字列のコピー

    ecoFileListに文字列をコピーしたいのですが、エラーになります。 どなたか教えて下さい int DML_Backup::searchEcoDataFileName(char (*ecoFileList)[32]) { map_type files; WIN32_FIND_DATA find_data; HANDLE handle = FindFirstFile("*.ecd", &find_data); if ( handle != INVALID_HANDLE_VALUE) { do { files.insert(map_type::value_type( find_data.ftLastWriteTime, find_data.cFileName)); } while ( FindNextFile( handle, &find_data) ); FindClose(handle); } for ( map_type::iterator iter = files.begin(); iter != files.end(); ++iter ) { lstrcpy(*ecoFileList, iter->second); ecoFileList++; } }

  • C++ の map についてです

    C++の初心者です。よろしくお願いします。 DirectXを使っていて簡単なゲームを作っていまして、 mapを使っていると、このようなエラーが出てしまいどうしても理由わかりませんでした。 class D2DMap : public GameTexture{ protected: GameTexture** CopyTexture; int MaxMass; int WidthMass; int HeightMass; int WidthMassPixel; int HeightMassPixel; int MassInfo[30][30]; public: D2DMap(); virtual ~D2DMap(); HRESULT LoadMapTexture(int widthmass, int widthmasspixel,int heightmass, int heightmasspixel, const char* FileName, D3DCOLOR color); HRESULT LoadTextMass(const char* FileName); int GetWidthMassPixel(){ return WidthMassPixel;} int GetWidthMassNum(){ return WidthMass;} int GetHeightMassPixel(){ return HeightMassPixel;} int GetHeightMassNum(){ return HeightMass;} int GetMassInfo(int x, int y){ return MassInfo[y][x];} void DrawMap(D3DCOLOR color); void DrawCopyMap(D3DCOLOR color); void SetCopyTex(GameTexture* copy){ CopyTexture= &copy;} void Delete(){} }; map<string , D2DMap*> MapBox; と定義して string Name="--------"; D2DMap map; MapBox.insert( map<string, D2DMap*>::value_type(Name, &map)); としたとこと error C2275: 'std::string' : この型は演算子として使用できません 'std::string' の宣言を確認してください。 error C2059: 構文エラー : '>' error C2039: 'value_type' : '`global namespace'' のメンバではありません というエラーが出てきました。 mapのfind や iterator は可能なのですがinsertの場合エラー となり、理由が全く分かりません。詳しい方アドバイスをお願いしたい のですが、よろしくお願いします。 VC++2008 を使っています。

  • 2つのリストのマージ方法について

    2つのリストのマージ方法について 下記の要件を満たしたいと考えています。 ・リスト1・2をkeyをキーにマージしたい。  リスト1[0]:key=2, value1=b  リスト1[1]:key=3, value1=d  リスト1[2]:key=4, value1=e  ・  ・  ・  リスト2[0]:key=1, value2=A  リスト2[1]:key=2, value2=B  リスト2[2]:key=5, value2=F  リスト2[3]:key=6, value2=G  ・  ・  ・  ↓  リスト3[0]:key=1, value1=A, value=""  リスト3[1]:key=2, value1=b, value=B  リスト3[2]:key=3, value1=d, value=""  リスト3[3]:key=4, value1=e, value=""  リスト3[4]:key=5, value1="", value=F  リスト3[5]:key=6, value1="", value=G  ・  ・  ・ ・リスト1・2はkeyの昇順でソート済。各リスト内では重複しているkeyはない。 ・マージ後もkeyの昇順にしたい。 ・実際のリストはそれぞれ数万件~数十万件なので、パフォーマンスを考慮したい。 下記のように作成してみたのですが、無理やりやりました感があり、分かりづらくバグがありそうです。またループでnewもしてたりしてパフォーマンスも悪そうです。もっとスマートにパフォーマンスもよい方法がないでしょうか? int checkedCount = 0; for (int i = 0; i < list1.size(); i++) { String str1 = list1.get(i).get("key"); for (int j = checkedCount; j < list2.size(); j++) { Map<String, String> map3 = new HashMap<String, String>(); String str2 = list2.get(j).get("key"); if (str1.compareTo(str2) < 0) { if (i != list1.size() - 1) { map3.put("key", str1); map3.put("value1", list1.get(i).get("value1")); map3.put("value2", ""); list3.add(map3); break; } else { Map<String, String> map4 = new HashMap<String, String>(); map4.put("key", str2); map4.put("value1", ""); map4.put("value2", list2.get(j).get("value2")); list3.add(map4); } } else if (str1.compareTo(str2) == 0) { map3.put("key", str1); map3.put("value1", list1.get(i).get("value1")); map3.put("value2", list2.get(j).get("value2")); list3.add(map3); checkedCount = j + 1; break; } else { map3.put("key", str2); map3.put("value1", ""); map3.put("value2", list2.get(j).get("value2")); list3.add(map3); checkedCount = j + 1; } } }

    • ベストアンサー
    • Java
  • パックマンプログラム

    パックマンプログラムを作っているんですが以下のように壁にぶつかってゲームオーバーになります。すべてのエサを食べさせたいんですがどのように以下のプログラムを改良すればいいですか? map(MAPDATA型):マップの情報(通路・エさ・壁の位置) p(POSITION型):プレイヤーの位置情報 e(POSITION型):モンスターの位置情報 0:通路 1:エサ 2:壁 プレイヤーのx座標:p.x,モンスターのy座標:e.y MAP_WIDTH:マップの横幅 (19) MAP_HEIGHT:マップの縦幅 (22) NUM_FOOD:エサの最大数 (156) #include <stdio.h> #include "Info.h" #include "math.h" MOVEMENT playerAI(MAPDATA map, POSITION p, POSITION e) { if (abs(p.x - e.x) + abs(p.y - e.y) <= 2) { return UP; }; if (map[p.y][p.x + 1] == 1) { return RIGHT; } else if (map[p.y + 1][p.x] == 1) { return DOWN; } else if (map[p.y][p.x - 1] == 1) { return LEFT; } else if (map[p.y - 1][p.x] == 1) { return UP; } else { return STAY; } Game.cpp http://codepad.org/C2opgSUX Red AI.cpp http://codepad.org/zlwvnPTX

  • ファイル名のリスト取得について2

    windowsで任意のフォルダにあるファイル名のリストを取得する方法を教えて頂きました。 ※例えば*.ecdのファイルリストを取得する場合です。 これを作成された日付が古い順に取得する事は出来ますでしょうか #include <windows.h> #include <stdio.h> int main() { WIN32_FIND_DATA ffd; HANDLE h = FindFirstFile("d:\\work\\*.ecd", &ffd); if ( h != INVALID_HANDLE_VALUE ) { do { puts(ffd.cFileName); } while ( FindNextFile(h, &ffd) ); FindClose(h); } }

  • googlemap api での 座標の取得

    googlemap apiを使って地図上をクリックしたところに 吹き出しをつくり、その中のフォームに情報を入力するという ページを作成してます。 が、うまく座標がとれません。 GEvent.addListener(map, 'click', function(overlay, point) { if (point) { document.getElementById("show_x").innerHTML = point.x; document.getElementById("show_y").innerHTML = point.y; map.openInfoWindowHtml(point,"<form><tableborder=1><tr><td><input type=text id=\"show_x\"><input type=text id=\"show_y\"></td></tr>); としていますが、show_x show_y が <input type=text value=***> のところに 入りません。 <body> 緯度<p id="show_x"></p> 経度<p id="show_y"></p> </body> のところには表示されます。

  • C言語

    *.cファイルを検索するんですがmain.cのファイルだけを検索しないようにするにはどう付け加えればいいでしょうか? void DoFind() { HANDLE hFind; WIN32_FIND_DATA fd; FILETIME ft; SYSTEMTIME st; /* 最初のファイル検索 */ hFind = FindFirstFile("*.c", &fd); /* 検索失敗? */ if(hFind == INVALID_HANDLE_VALUE) { printf("検索失敗\n"); return; /******** エラー終了 ********/ } do { /* 結果の表示 */ printf("ファイル名: %s", fd.cFileName); } while(FindNextFile(hFind, &fd)); '次のファイルを検索 /* 検索終了 */ FindClose(hFind); }

  • メソッドの呼び出し方

    サブクラスを記述する下記のプログラムについて質問します。 class Car { //タイヤ private String tire = ""; public Car() { tire = "タイヤ"; } /* *どんなタイヤであるかを設定 *value タイヤの種類 */ public void setTire(String value) { tire = value + "のタイヤ"; } /* *作成されたタイヤを返します *return タイヤ */ public String getTire() { return tire; } } class Motorcar extends Car { private String tire = ""; private String body = ""; private String handle = ""; String type = ""; public Motorcar() { tire = "タイヤ"; body = "車体"; handle = "ハンドル"; } public String getTire() { return tire; } public String getBody() { return body; } public String getHandle() { return handle; } public String createMotorcar(String t) { type = t; tire = type + "のタイヤ"; return tire; } } public class Sample1 { public static void main(String atgs[]) { Motorcar car = new Motorcar(); String type = "トラック"; String tire = car.getTire(); String body = car.getBody(); String handle = car.getHandle(); System.out.println("タイヤ=" + tire); System.out.println("車体=" + body); System.out.println("ハンドル=" + handle); //どんな車かを設定 car.createMotorcar(type); tire = car.getTire(); body = car.getBody(); handle = car.getHandle(); System.out.println(type + "の作成!!"); System.out.println("タイヤ=" + tire); System.out.println("車体=" + body); System.out.println("ハンドル=" + handle); } } これを実行したら、 タイヤ = タイヤ 車体 = 車体 ハンドル = ハンドル トラックの作成!! タイヤ = トラックのタイヤ 車体 = 車体 ハンドル = ハンドル となりました。 後半の車体・ハンドルにも「トラックの」という言葉 を入れるには、どういうふうにメソッドを記述したらよいのでしょうか? ちなみに問題では、サブクラスだけ自分で記述し、スーパークラス・ 実行クラスはこのまま利用することとします。

    • ベストアンサー
    • Java
  • HANDLEて何ですか?

    #include <windows.h> #include <stdio.h> #include <conio.h> int Locate(HANDLE, int, int); int TxtPrint(HANDLE, char *); int main() { HANDLE hStdout; SYSTEMTIME st; char str[32]; hStdout = GetStdHandle(STD_OUTPUT_HANDLE); while(!_kbhit()) { Locate(hStdout, 0, 10); GetLocalTime(&st); wsprintf(str, "現在%2d時%2d分%2d秒です", st.wHour, st.wMinute, st.wSecond); TxtPrint(hStdout, str); Sleep(500); } return 0; } int Locate(HANDLE hOut, int x, int y) { COORD dwPos; dwPos.X = (SHORT)x; dwPos.Y = (SHORT)y; if (SetConsoleCursorPosition(hOut, dwPos) == 0) return -1; else return 0; } int TxtPrint(HANDLE hOut, char *str) { BOOL bResult; DWORD dwResult; bResult = WriteConsole(hOut, (CONST VOID *)str, (DWORD)lstrlen(str), &dwResult, NULL); if (bResult == 0) return -1; else return 0; } よくハンドルと言う言葉が出てくるのですが、いまいち意味がわかりません。あとint Locate()の所で COORD dwPos; dwPos.X = (SHORT)x; dwPos.Y = (SHORT)y; とやっているのですが、これは?

専門家に質問してみよう