我正在撕掉我的頭髮在這個錯誤。試圖寫一個文本字段值在C++中的文件
------ Build started: Project: shotfactorybatchgen, Configuration: Debug Win32 ------
shotfactorybatchgen.cpp
c:\documents and settings\administrator\my documents\visual studio 2010\projects\shotfactorybatchgen\shotfactorybatchgen\Form1.h(307): error C2664: 'fprintf' : cannot convert parameter 2 from 'System::String ^' to 'const char *'
No user-defined-conversion operator available, or
Cannot convert a managed type to an unmanaged type
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
我看過周圍所有的interwebs,但我找不到答案。這裏是錯誤發生的代碼。
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
Decimal value;
if(!Decimal::TryParse(textBox4->Text, value)) {
MessageBox::Show("Non-numeric characters detected in 'Wait Time' filed", "Oops", MessageBoxButtons::OK, MessageBoxIcon::Warning);
} else {
if(!Decimal::TryParse(textBox3->Text, value)) {
MessageBox::Show("Non-numeric characters detected in 'Max Upload' filed", "Oops", MessageBoxButtons::OK, MessageBoxIcon::Warning);
} else {
FILE *OutFile = fopen("run.bat","w");
fprintf(OutFile,"@ECHO OFF\r\nC:\\Python26\\python.exe factory.py");
if(factoryname->Text != ""){
fprintf(OutFile," -f ");
fprintf(OutFile,factoryname->Text);
}
fclose(OutFile);
}
}
}
任何想法?這是一個簡單的Windows窗體應用程序。我使用Visual Studio C++ 2010
感謝
科拉姆
您使用的語言稱爲C++/CLI - 與標準C++非常不同。如果使用正確的名稱來搜索類似問題的答案,它可能會有所幫助。我已經相應地重新標記了你的問題。 – 2010-07-03 00:31:07