2012-11-28 73 views
0

我使用SaveFileDialog class example 結合使用創建一個用戶定義的目錄中的文本文件。VC++的iostream/savefiledialog錯誤

這裏是我的代碼有衝突的部分:

private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { 
      array<Image^> ^imageArray ; 
      int CurrentImage=0; 
      imageArray = gcnew array<Image^>(9); 
      array<String^>^ names = {L"adc1.bmp" ,"adc2.bmp","adc3.bmp","adc4.bmp","adc5.bmp","adc6.bmp","adc7.bmp","adc8.bmp"}; 
      for(int i=0; i<8; i++) 
      { 
       System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid)); 
       imageArray[i] =(cli::safe_cast<System::Drawing::Bitmap^>(resources->GetObject(names[i]))); 
      } 

      if((this->comboBox4->Text == String::Empty)||(this->textBox2->Text == String::Empty)){ 
       this->textBox1->Text="please select port and save file directory"; 

      } 


      else{ // start assigning 
       try{ // first make sure port isn't busy/open 
        if(!this->serialPort1->IsOpen){ 
         // select the port whose name is in comboBox4 (select port) 
         this->serialPort1->PortName=this->comboBox4->Text; 
         //open the port 
         this->serialPort1->Open(); 
         // sending 
         String^ name_ = this->serialPort1->PortName; 
         String^ START; 
         int m=0; 
         //send data to setup timer on the microcontroller 
         this->serialPort1->WriteLine(START); 
         Stream^ myStream; 
         SaveFileDialog^ saveFileDialog1 = gcnew SaveFileDialog; 
         saveFileDialog1->Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"; 
         saveFileDialog1->FilterIndex = 2; 
         saveFileDialog1->RestoreDirectory = true; 
         if (saveFileDialog1->ShowDialog() == System::Windows::Forms::DialogResult::OK ) 
         { 
          if ((myStream = saveFileDialog1->OpenFile()) != nullptr) 
          { 
           // receiving 
           myStream<<"ADC1;ADC2;ADC3;ADC4;ADC5;ADC6;ADC7;ADC8"<<endl; 
           while(START){ 
            myStream<<this->serialPort1->ReadLine()<<";"; 
            pictureBox1->image=imagearray[m]; 
            m++; 
            if(m==7){ 
             myStream<<endl; 
             m=0; 
            } 
           } 
          }}} 
        else{ 
         this->textBox1->Text="Warning: port is busy or isn't open"; 
        } 
       } 
       catch(UnauthorizedAccessException^){ 
        this->textBox1->Text="Unauthorized access"; 
       } 
      } 

     } 

不過,我發現了以下錯誤:

1>------ Build started: Project: Data_Logger, Configuration: Debug Win32 ------ 
1> Data_Logger.cpp 
1>c:\documents and settings\310098394\desktop\programming\visual c++\data_logger\data_logger\Form1.h(301): error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,const std::error_code &)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'System::IO::Stream ^' 
1>   C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ostream(1085) : see declaration of 'std::operator <<' 
1>c:\documents and settings\310098394\desktop\programming\visual c++\data_logger\data_logger\Form1.h(301): error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &&,_Ty)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &&' from 'System::IO::Stream ^' 
1>   C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ostream(968) : see declaration of 'std::operator <<' 
1>c:\documents and settings\310098394\desktop\programming\visual c++\data_logger\data_logger\Form1.h(301): error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,unsigned char)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'System::IO::Stream ^' 
1>   C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ostream(958) : see declaration of 'std::operator <<' 
1>c:\documents and settings\310098394\desktop\programming\visual c++\data_logger\data_logger\Form1.h(301): error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,const unsigned char *)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'System::IO::Stream ^' 
1>   C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ostream(951) : see declaration of 'std::operator <<' 
1>c:\documents and settings\310098394\desktop\programming\visual c++\data_logger\data_logger\Form1.h(301): error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,signed char)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'System::IO::Stream ^' 
1>   C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ostream(944) : see declaration of 'std::operator <<' 
1>c:\documents and settings\310098394\desktop\programming\visual c++\data_logger\data_logger\Form1.h(301): error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,const signed char *)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'System::IO::Stream ^' 
1>   C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ostream(937) : see declaration of 'std::operator <<' 
1>c:\documents and settings\310098394\desktop\programming\visual c++\data_logger\data_logger\Form1.h(301): error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,_Elem)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'System::IO::Stream ^' 
1>   C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ostream(898) : see declaration of 'std::operator <<' 
1>c:\documents and settings\310098394\desktop\programming\visual c++\data_logger\data_logger\Form1.h(301): error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,const _Elem *)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'System::IO::Stream ^' 
1>   C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ostream(851) : see declaration of 'std::operator <<' 
1>c:\documents and settings\310098394\desktop\programming\visual c++\data_logger\data_logger\Form1.h(301): error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,char)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'System::IO::Stream ^' 
1>   C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ostream(811) : see declaration of 'std::operator <<' 
1>c:\documents and settings\310098394\desktop\programming\visual c++\data_logger\data_logger\Form1.h(301): error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,const char *)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'System::IO::Stream ^' 
1>   C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ostream(764) : see declaration of 'std::operator <<' 
1>c:\documents and settings\310098394\desktop\programming\visual c++\data_logger\data_logger\Form1.h(301): error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,char)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'System::IO::Stream ^' 
1>   C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ostream(726) : see declaration of 'std::operator <<' 
1>c:\documents and settings\310098394\desktop\programming\visual c++\data_logger\data_logger\Form1.h(301): error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,const char *)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'System::IO::Stream ^' 
1>   C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ostream(679) : see declaration of 'std::operator <<' 
1>c:\documents and settings\310098394\desktop\programming\visual c++\data_logger\data_logger\Form1.h(301): error C2676: binary '<<' : 'System::IO::Stream ^' does not define this operator or a conversion to a type acceptable to the predefined operator 
1>c:\documents and settings\310098394\desktop\programming\visual c++\data_logger\data_logger\Form1.h(304): error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,const std::error_code &)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'System::IO::Stream ^' 
1>   C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ostream(1085) : see declaration of 'std::operator <<' 
1>c:\documents and settings\310098394\desktop\programming\visual c++\data_logger\data_logger\Form1.h(304): error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &&,_Ty)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &&' from 'System::IO::Stream ^' 
1>   C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ostream(968) : see declaration of 'std::operator <<' 
1>c:\documents and settings\310098394\desktop\programming\visual c++\data_logger\data_logger\Form1.h(304): error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,unsigned char)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'System::IO::Stream ^' 
1>   C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ostream(958) : see declaration of 'std::operator <<' 
1>c:\documents and settings\310098394\desktop\programming\visual c++\data_logger\data_logger\Form1.h(304): error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,const unsigned char *)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'System::IO::Stream ^' 
1>   C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ostream(951) : see declaration of 'std::operator <<' 
1>c:\documents and settings\310098394\desktop\programming\visual c++\data_logger\data_logger\Form1.h(304): error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,signed char)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'System::IO::Stream ^' 
1>   C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ostream(944) : see declaration of 'std::operator <<' 
1>c:\documents and settings\310098394\desktop\programming\visual c++\data_logger\data_logger\Form1.h(304): error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,const signed char *)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'System::IO::Stream ^' 
1>   C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ostream(937) : see declaration of 'std::operator <<' 
1>c:\documents and settings\310098394\desktop\programming\visual c++\data_logger\data_logger\Form1.h(304): error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,_Elem)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'System::IO::Stream ^' 
1>   C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ostream(898) : see declaration of 'std::operator <<' 
1>c:\documents and settings\310098394\desktop\programming\visual c++\data_logger\data_logger\Form1.h(304): error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,const _Elem *)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'System::IO::Stream ^' 
1>   C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ostream(851) : see declaration of 'std::operator <<' 
1>c:\documents and settings\310098394\desktop\programming\visual c++\data_logger\data_logger\Form1.h(304): error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,char)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'System::IO::Stream ^' 
1>   C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ostream(811) : see declaration of 'std::operator <<' 
1>c:\documents and settings\310098394\desktop\programming\visual c++\data_logger\data_logger\Form1.h(304): error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,const char *)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'System::IO::Stream ^' 
1>   C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ostream(764) : see declaration of 'std::operator <<' 
1>c:\documents and settings\310098394\desktop\programming\visual c++\data_logger\data_logger\Form1.h(304): error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,char)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'System::IO::Stream ^' 
1>   C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ostream(726) : see declaration of 'std::operator <<' 
1>c:\documents and settings\310098394\desktop\programming\visual c++\data_logger\data_logger\Form1.h(304): error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,const char *)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'System::IO::Stream ^' 
1>   C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ostream(679) : see declaration of 'std::operator <<' 
1>c:\documents and settings\310098394\desktop\programming\visual c++\data_logger\data_logger\Form1.h(304): error C2676: binary '<<' : 'System::IO::Stream ^' does not define this operator or a conversion to a type acceptable to the predefined operator 
1>c:\documents and settings\310098394\desktop\programming\visual c++\data_logger\data_logger\Form1.h(305): error C2039: 'image' : is not a member of 'System::Windows::Forms::PictureBox' 
1>   c:\program files\reference assemblies\microsoft\framework\.netframework\v4.0\system.windows.forms.dll : see declaration of 'System::Windows::Forms::PictureBox' 
1>c:\documents and settings\310098394\desktop\programming\visual c++\data_logger\data_logger\Form1.h(305): error C2065: 'imagearray' : undeclared identifier 
1>c:\documents and settings\310098394\desktop\programming\visual c++\data_logger\data_logger\Form1.h(308): error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,const std::error_code &)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'System::IO::Stream ^' 
1>   C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ostream(1085) : see declaration of 'std::operator <<' 
1>c:\documents and settings\310098394\desktop\programming\visual c++\data_logger\data_logger\Form1.h(308): error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &&,_Ty)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &&' from 'System::IO::Stream ^' 
1>   C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ostream(968) : see declaration of 'std::operator <<' 
1>c:\documents and settings\310098394\desktop\programming\visual c++\data_logger\data_logger\Form1.h(308): error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,unsigned char)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'System::IO::Stream ^' 
1>   C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ostream(958) : see declaration of 'std::operator <<' 
1>c:\documents and settings\310098394\desktop\programming\visual c++\data_logger\data_logger\Form1.h(308): error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,const unsigned char *)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'System::IO::Stream ^' 
1>   C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ostream(951) : see declaration of 'std::operator <<' 
1>c:\documents and settings\310098394\desktop\programming\visual c++\data_logger\data_logger\Form1.h(308): error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,signed char)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'System::IO::Stream ^' 
1>   C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ostream(944) : see declaration of 'std::operator <<' 
1>c:\documents and settings\310098394\desktop\programming\visual c++\data_logger\data_logger\Form1.h(308): error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,const signed char *)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'System::IO::Stream ^' 
1>   C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ostream(937) : see declaration of 'std::operator <<' 
1>c:\documents and settings\310098394\desktop\programming\visual c++\data_logger\data_logger\Form1.h(308): error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,_Elem)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'System::IO::Stream ^' 
1>   C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ostream(898) : see declaration of 'std::operator <<' 
1>c:\documents and settings\310098394\desktop\programming\visual c++\data_logger\data_logger\Form1.h(308): error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,const _Elem *)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'System::IO::Stream ^' 
1>   C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ostream(851) : see declaration of 'std::operator <<' 
1>c:\documents and settings\310098394\desktop\programming\visual c++\data_logger\data_logger\Form1.h(308): error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,char)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'System::IO::Stream ^' 
1>   C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ostream(811) : see declaration of 'std::operator <<' 
1>c:\documents and settings\310098394\desktop\programming\visual c++\data_logger\data_logger\Form1.h(308): error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,const char *)' : could not deduce template argument for 'std::basic_ostream<char,_Traits> &' from 'System::IO::Stream ^' 
1>   C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ostream(764) : see declaration of 'std::operator <<' 
1>c:\documents and settings\310098394\desktop\programming\visual c++\data_logger\data_logger\Form1.h(308): error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,char)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'System::IO::Stream ^' 
1>   C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ostream(726) : see declaration of 'std::operator <<' 
1>c:\documents and settings\310098394\desktop\programming\visual c++\data_logger\data_logger\Form1.h(308): error C2784: 'std::basic_ostream<_Elem,_Traits> &std::operator <<(std::basic_ostream<_Elem,_Traits> &,const char *)' : could not deduce template argument for 'std::basic_ostream<_Elem,_Traits> &' from 'System::IO::Stream ^' 
1>   C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ostream(679) : see declaration of 'std::operator <<' 
1>c:\documents and settings\310098394\desktop\programming\visual c++\data_logger\data_logger\Form1.h(308): error C2676: binary '<<' : 'System::IO::Stream ^' does not define this operator or a conversion to a type acceptable to the predefined operator 
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== 

錯誤開始於行:myStream<<"ADC1;ADC2;ADC3;ADC4;ADC5;ADC6;ADC7;ADC8"<<endl;

我用ofstream之前和它的工作。不過,我想用戶選擇的目錄,並命名輸出文件,我不知道是否會使用ofstream是可能的。我真的很感激,如果有人可以幫助我解決在至少涉及到myStream錯誤。

在此先感謝

+0

你不能與非託管混合的託管Stream類'

回答