如何将此c ++函数转换为c#?

时间:2014-02-18 08:04:22

标签: c# c++

我尝试使用在线转换器,但它没有成功。

C ++功能如下。我希望它在c#中等效。

//! Save the SURF features to file
void saveSurf(char *filename, vector<Ipoint> &ipts)
{
  ofstream outfile(filename);

  // output descriptor length
  outfile << "64\n";
  outfile << ipts.size() << "\n";

  // create output line as:  scale  x  y  des
  for(unsigned int i=0; i < ipts.size(); i++) 
  {
    outfile << ipts.at(i).scale << "  ";
    outfile << ipts.at(i).x << " ";
    outfile << ipts.at(i).y << " ";
    outfile << ipts.at(i).orientation << " ";
    outfile << ipts.at(i).laplacian << " ";
    outfile << ipts.at(i).scale << " ";
    for(int j=0; j<64; j++)
      outfile << ipts.at(i).descriptor[j] << " ";

    outfile << "\n";
  }

  outfile.close();
}

我认为ofstream是streamwriter或者可能是文件流。

1 个答案:

答案 0 :(得分:1)

使用TextWriter类。

using (StreamWriter writer = File.CreateText("file.txt"))
{
    writer.WriteLine("64");
    // etc.
}

或异步:

using (StreamWriter writer = File.CreateText("file.txt"))
{
    await writer.WriteLineAsync("64");
    // etc.
}