Desktop-Pfad???
-
ne ich will das Programm unter die Leute bringen. Da ist es nicht toll, wenn die meinen Pfad verwenden müssen!
Und
datei.open("...\\...\\desktop\\The List.txt", ios_base::out);funktioniert nicht!
-
SHGetFolderPath() mit Parameter CSIDL_DESKTOP
http://msdn.microsoft.com/en-us/library/bb762181(v=vs.85).aspx
-
Ich kapiers nicht!
-
Ich lesegerade, dass SHGetFolderath() "deprecated" ist, aber das: http://msdn.microsoft.com/en-us/library/bb762188 kapiere ich auf die Schnelle nicht

Was hast du denn für einen Code mit SHGetFolderPath() und welche Fehler?
-
Ok. ich habs ausprobiert. ich brauchs aber als std::string oder char[].
-
Im Beispiel ist ein TCHAR, was nichts anderes als wchar_t ist. Also hilft dir da std::wstring.
Edit: Und wenn du dann wirklich einen std::string brauchst dann hilft dir sicher diese Funktion:
// Convert a wide Unicode string to an UTF8 string std::string utf8_encode(const std::wstring &wstr) { int size_needed = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), NULL, 0, NULL, NULL); std::string strTo( size_needed, 0 ); WideCharToMultiByte (CP_UTF8, 0, &wstr[0], (int)wstr.size(), &strTo[0], size_needed, NULL, NULL); return strTo; }
-
LPTSTR ist doch ein char* oder wchar_t*, jenachdem ob du UNICODE definiert hast oder nicht

-
TCHAR pzPath[MAX_PATH]; cout << "Welcome!\n\n\n" << "This is your personal 'List Editor'.\n" << "You can type in several things. This program will sort them and also count them!\n\n\n" << "Press any key to start!" << SHGetFolderPath(NULL, CSIDL_DESKTOP, NULL, 0, pzPath) << pzPath;Ergebnis:
Welcome! This is your personal 'List Editor'. You can type in several things. This program will sort them and also count them! Press any key to start!00012FD58Das kommt raus, wenn ich das so mache:
TCHAR pzPath[MAX_PATH]; cout << "Welcome!\n\n\n" << "This is your personal 'List Editor'.\n" << "You can type in several things. This program will sort them and also count them!\n\n\n" << "Press any key to start!" << SHGetFolderPath(NULL, CSIDL_DESKTOP, NULL, 0, pzPath) << pzPath << utf8_encode(pzPath);Welcome! This is your personal 'List Editor'. You can type in several things. This program will sort them and also count them! Press any key to start!00012FD4Cý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│î ý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│ îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý │îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│î ý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│ îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý │îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│î ý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│ îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý │îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│îý│î ý│îý│îý│îý│îý│îý│îÚ½çþïì´¥¿↕¯ÇèA´┐┐´┐┐´¥©↕Ùê¿A☺
-
Bei mir funktioniert... Hilfreich ist es wcout zu verwenden wenn man einen WIDECHAR hat.
#include <iostream> #include <windows.h> #include <tchar.h> #include <Shlobj.h> using namespace std; int main(void) { TCHAR szPath[MAX_PATH]; SHGetFolderPath(NULL, CSIDL_DESKTOP, NULL, 0, szPath); wcout << szPath; }
-
Gut, in szPath ist jetzt der Pfad. Aber wie kann ich szPath zu char[] oder std:string konvertieren? open will nämlich char[] als Pfad!
-
Du Aussage std::wstring = TCHAR sollte helfen und dieser Link
http://www.c-plusplus.net/forum/278658Edit: Nur mal so am Rand es gibt auch wifstream, wofstream, etc. die verlangen dann statt chars wchar_t was = TCHAR ist.
-
Fertig!!!
Funktioniert. Text ist (leider) auf Englisch. Aber ich denke, wenn ihr es lest, dann versteht ihr es schon!#include <iostream> #include <fstream> #include <string> #include <map> #include <Shlobj.h> #include <windows.h> #include <tchar.h> using namespace std; string utf8_encode(const wstring &wstr) { int size_needed = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], (int)wstr.size(), NULL, 0, NULL, NULL); string strTo( size_needed, 0 ); WideCharToMultiByte (CP_UTF8, 0, &wstr[0], (int)wstr.size(), &strTo[0], size_needed, NULL, NULL); return strTo; } string trim(string& str) { while((str[0] == '\n') || (str[0] == ' ') || (str[0] == '\t')) str = str.substr(1); return str; } string trim(string str) { while((str[0] == '\n') || (str[0] == ' ') || (str[0] == '\t')) str = str.substr(1); return str; } map<string, int> read_in() { map<string, int> content; string ram; cout << "\n\nPlease type in your names. To end this Stream type only: 'e'\n"; do { cout << "\nNext:"; getline(cin, ram); if(ram != "e") content[ram]++; }while(ram != "e"); return content; } void make_list(map<string, int> content) { ofstream datei; TCHAR pzPath[MAX_PATH]; typedef map<string, int>::iterator iterTyp; SHGetFolderPath(NULL, CSIDL_DESKTOP, NULL, 0, pzPath); datei.open((utf8_encode(pzPath) + "\\The List.txt").c_str(), ios_base::out); datei << "Name:"; for(iterTyp it = content.begin(); it != content.end(); ++it) { datei << "\n" << it->first; if(it->second != 1) datei << " x " << (it->second); } datei.close(); cout << "Name:"; for(iterTyp it = content.begin(); it != content.end(); ++it) { cout << "\n" << it->first; if(it->second != 1) cout << " x " << (it->second); } } int main() { cout << "Welcome!\n\n\n" << "This is your personal 'List Editor'.\n" << "You can type in several things. This program will sort them and also count them!\n\n\n" << "Press any key to start!"; cin.get(); make_list(read_in()); cout << "\n\nEverything is done.\n\n" << "You'll find the list on your desktop with the name 'The List'!\n\n\n" << "Press any key to quit!"; cin.get(); return 0; }Danke an euch alle!
-
Nur mal so am Rand es gibt auch wifstream, wofstream, etc. die verlangen dann statt chars wchar_t was = TCHAR ist.