首先,我是硬件编程人员(HDL,uC编程),几天前我的老板问我在Visual C++中创建了一个用于控制uC的接口。我以前从未使用过Visual C++,而且我的软件编程技能最好是中级。但是,我只有到周二才能使界面工作,因此我不得不寻找示例,并根据我的时间框架执行相同的操作。所以请原谅我,如果我问任何明显和愚蠢的问题。visual C++ fstream error
在我的代码中,我必须将存储在数组中的值移动到CSV文件中。所以我必须使用逗号分隔我的值... 但是,为了创建一个CSV文件,我必须使用fstream(据我所知,迄今为止我已经了解)。 每当我使用
#include <fstream>
我得到一个巨大的错误,如量:
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(244): error C3083: 'vc_attributes': the symbol to the left of a '::' must be a type
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\codeanalysis\sourceannotations.h(244): error C2039: 'YesNoMaybe' : is not a member of '`global namespace''
这里是我的代码fstream的相关休息:
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::IO::Ports;
#include <iostream>
#include <fstream>
std::ofstream myfile;
myfile.open("Data.txt");
//find available ports
private: void findports(void){
array<Object^>^ objectArray = SerialPort::GetPortNames();
this->comboBox4->Items->AddRange(objectArray);
array<String ^>^h = gcnew array<String ^>(24);
for(int i=0; i<=23; i++){
h[i]= String::Concat(i.ToString());
}
this->comboBox1->Items->AddRange(h);
array<String ^>^m = gcnew array<String ^>(60);
for(int i=0; i<=59; i++){
m[i]= String::Concat(i.ToString());
}
this->comboBox3->Items->AddRange(m);
array<String ^>^s = gcnew array<String ^>(24);
for(int i=0; i<=23; i++){
s[i]= String::Concat(i.ToString());
}
this->comboBox5->Items->AddRange(s);
array<String ^>^d = gcnew array<String ^>(366);
for(int i=0; i<=365; i++){
d[i]= String::Concat(i.ToString());
}
this->comboBox2->Items->AddRange(d);
}
private: System::Void label1_Click(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void label2_Click(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void label4_Click(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void label5_Click(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void label6_Click(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
if((this->comboBox4->Text == String::Empty)||(this->textBox1->Text == String::Empty)||(this->textBox2->Text == String::Empty)){
this->textBox1->Text="missing port settings";
this->textBox2->Text="missing port settings";
}
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^ sampling_period_ = this->comboBox5->Text;
String^ days_ = this->comboBox2->Text;
String^ hours_ = this->comboBox3->Text;
String^ minutes_ = this->comboBox1->Text;
String^ start_ = this->textBox1->Text;
String^ end_ = this->textBox2->Text;
//send data to setup timer on the microcontroller
this->serialPort1->WriteLine(sampling_period_);
this->serialPort1->WriteLine(days_);
this->serialPort1->WriteLine(hours_);
this->serialPort1->WriteLine(minutes_);
// send slave addresses
this->serialPort1->WriteLine(start_);
this->serialPort1->WriteLine(end_);
// receiving
int rec[100][8];
for (int i=0;i<sizeof(rec[0]);i++){
for (int j=0;j<sizeof(rec);j++){
rec[i][j]=int::Parse(this->serialPort1->ReadLine());
}
}
myfile<<"ADC1"<<","<<"ADC2"<<","<<"ADC3"<<","<<"ADC4"<<","<<"ADC5"<<","<<"ADC6"<<","<<"ADC7"<<","<<"ADC8"<<endl;
for (int i=0;i<sizeof(rec[0]);i++){
for (int j=0;j<sizeof(rec);j++){
myfile<<rec[i][j]<<",";
}
myfile<<endl;
}
}
else{
this->textBox1->Text="Warning: port is busy or isn't open";
this->textBox2->Text="Warning: port is busy or isn't open";
}
}
catch(UnauthorizedAccessException^){
this->textBox1->Text="Unauthorized access";
this->textBox2->Text="Unauthorized access";
}
}
}
private: System::Void textBox1_TextChanged(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void label7_Click(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void label8_Click(System::Object^ sender, System::EventArgs^ e) {
}
};
}
我希望能得到一些帮助或至少在这里有用的信息。
在此先感谢。
错误消息看起来不像他们与这里提供的代码有任何关系。请张贴真实的代码,这是你能想出的最短的代码,可以证明问题。 –
你没有显示出足够的数据......你能发布更多的代码吗?特别是你自己的任何包括。如果你在内置的头文件中出错,这可能意味着你自己缺少一个分号,或者没有用相应的'#endif'关闭一个打开的'#if ????'子句。 – paddy
请勿多发表。帖子不同。 –