עבור לתוכן

שמירת קובץ ע"י תפריט

Featured Replies

פורסם
  • מחבר

סיימתי את החלק של השמירה של השלב, הכל עובד כמו שצריך עכשיו יש לי בעיה חדשה

בטעינה של השלב אני לא מבין איך אני קורא שורה שלמה (אין איזה getline גם ב.net)?

או אם יש דרך לפצל את המחרוזת לפי רווחים, אני חדש ב.net פשוט הפרוייקט הוא בc++ ולא למדנו את כל הנושאים הללו

תודה על הסבלנות

פורסם

למה אתה משתמש בmanaged c++ לדבר כל כך פשוט? זה זוועה של דבר והשימוש הטוב היחיד שלו זה למטרות interop

הרבה יותר פשוט להשתמש בפונקציית API שפותחת לך דיאלוג במקום להתעסק עם קוד .netי

הAPI שפותח תיבה הוא GetOpenFileName \ GetSaveFileName (בהתאם למה שאתה צריך), ואפשר למצוא איןספור דוגמאות שימוש בגוגל\MSDN

פורסם
  • מחבר

^ ניסיתי חלק מהדוגמאות שמצאתי בגוגל והוא נותן ים

זה הקוד של הפונקציה


OPENFILENAME ofn; // common dialog box structure
char szFile[260]; // buffer for file name
HWND hwnd; // owner window
HANDLE hf; // file handle

printf("initialising...\n");
// Initialize OPENFILENAME
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwnd;
ofn.lpstrFile = szFile;
//
// Set lpstrFile[0] to '\0' so that GetOpenFileName does not
// use the contents of szFile to initialize itself.
//
printf("setting...\n");
ofn.lpstrFile[0] = '\0';
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFilter = "All\0*.*\0Text\0*.TXT\0";
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;

ואלו השגיאות

1>.\Controller.cpp(142) : error C2440: '=' : cannot convert from 'char [260]' to 'LPWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>.\Controller.cpp(150) : error C2440: '=' : cannot convert from 'const char [20]' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>.\Controller.cpp(173) : error C2143: syntax error : missing ')' before ';'
1>.\Controller.cpp(173) : error C2660: 'System::IO::TextReader::ReadBlock' : function does not take 0 arguments
1>.\Controller.cpp(174) : error C2440: 'initializing' : cannot convert from 'const char [2]' to 'wchar_t [1]'

פורסם

אתה חייב להימנע מהתערובת הזו של Managed C++, STL ו-Windows API... תבחר API אחד ותעבוד רק איתו. אם כבר אתה עובד ב-Managed, אז כמו שאמרתי - תשתמש ב-FileStream ו-FileReader.

פורסם
  • מחבר

אני משתמש ב FileStream ואני קורא את השורות של הקובץ, הבעיה שיש לי זה הפרסוס של הנתונים בכל שורה

ואני מסתבך עם הsyntax ואני לא מוצא דוגמא נורמלית של spilt לstring ^ אם אתה יכול להסביר לי או להביא לינק שיסביר מה אני אמור לשלוח לפונקציה ולקבל

ממנה זה יהיה מעולה

פורסם

^ ניסיתי חלק מהדוגמאות שמצאתי בגוגל והוא נותן ים

זה הקוד של הפונקציה


OPENFILENAME ofn; // common dialog box structure
char szFile[260]; // buffer for file name
HWND hwnd; // owner window
HANDLE hf; // file handle

printf("initialising...\n");
// Initialize OPENFILENAME
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hwnd;
ofn.lpstrFile = szFile;
//
// Set lpstrFile[0] to '\0' so that GetOpenFileName does not
// use the contents of szFile to initialize itself.
//
printf("setting...\n");
ofn.lpstrFile[0] = '\0';
ofn.nMaxFile = sizeof(szFile);
ofn.lpstrFilter = "All\0*.*\0Text\0*.TXT\0";
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir = NULL;
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;

ואלו השגיאות

1>.\Controller.cpp(142) : error C2440: '=' : cannot convert from 'char [260]' to 'LPWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>.\Controller.cpp(150) : error C2440: '=' : cannot convert from 'const char [20]' to 'LPCWSTR'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>.\Controller.cpp(173) : error C2143: syntax error : missing ')' before ';'
1>.\Controller.cpp(173) : error C2660: 'System::IO::TextReader::ReadBlock' : function does not take 0 arguments
1>.\Controller.cpp(174) : error C2440: 'initializing' : cannot convert from 'const char [2]' to 'wchar_t [1]'

השגיאה כאן היא פשוטה מאוד, אתה מעביר מחרוזת ASCII ולא מחרוזת unicode.

פשוט תרשום L לפני כל מחרוזת שאמורה להיות יוניקוד (LPCWSTR זה בעצם typedef של פוינטר לunsigned short, שזה מקביל למחרוזת יוניקוד)

פורסם
  • מחבר

זה עדיין לא עוזר

פורסם

אני מסתבך עם הsyntax ואני לא מוצא דוגמא נורמלית של spilt לstring ^ אם אתה יכול להסביר לי או להביא לינק שיסביר מה אני אמור לשלוח לפונקציה ולקבל

ממנה זה יהיה מעולה

איך אתה לא מוצא דוגמה נורמלית?

http://msdn.microsoft.com/en-us/library/system.string.split.aspx

http://msdn.microsoft.com/en-us/library/b873y76a.aspx

פורסם
  • מחבר

הם לא מסבירים איך לעשות שם משהו(או ששוב אני לא מבין)

בכל מקרה זה הקוד שלי עד עכשיו:


FileStream^ fileStream = File::OpenRead( loadFileDialog->FileName );
try
{
StreamReader ^sr = gcnew StreamReader(fileStream);
while(sr->Peek() > -1)
{
String ^s = sr->ReadLine();

}
sr->Close();
}
finally
{
if ( fileStream )
delete (IDisposable^)fileStream;
}

כאשר כל פעם בs יש את השורה הנוחכית, בכל שורה יש 3 מספרים שמופרדים ברווח אני צריך לקלוט את שלושתם ל3 משתנים מסוג int לשימוש התוכנית

פורסם

בלינק שנתתי לך יש דוגמה ל-String.Split ב-#C. זה לא שונה בהרבה מקוד ה-C++/CLI שאתה צריך לכתוב.

דרך אגב, יש סיבה מיוחדת שאתה כותב בזוועה שנקראת C++/CLI ולא פשוט ב-#C?

פורסם
  • מחבר

אני צריך לכתוב את הפרוייקט בC++ פרט לחלק של הטעינה שמירה של קובץ שמתאר את השלב

בכל מקרה אני לא בקיא בכלל בSyntax של C#/.Net ובגלל זה אני שואל את כל השאלות הללו

אין איזה לינק שיסביר את זה כמו שצריך, אני גם לא מאמין שזה כזה סיפור לעשות את זה, הבעיה שאני יודע איך לעשות את זה בC++

עריכה:

הסתדרתי, תודה לכולם על העזרה

ארכיון

דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.

דיונים חדשים