我正在重写一些代码,想知道如何将其从 C++ 转换为 C#:
istringstream vertexString = new istringstream(s);
//number of vertices
int numVertices;
vertexString>>numVertices;
最佳答案
将其添加到静态字符串实用程序类:
public static Stream ToStream(this string str)
{
MemoryStream stream = new MemoryStream();
StreamWriter writer = new StreamWriter(stream);
writer.Write(str);
writer.Flush();
stream.Position = 0;
return stream;
}
这样使用。 s 必须是字符串。
int numVertices;
using (var stringStream = s.ToStream())
{
stringStream>>numVertices;
}
关于c# - 将 C++ istringstream 用法转换为 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35383670/