我正在重写一些代码并想知道如何将其从C ++转换为C#:
istringstream vertexString = new istringstream(s);
//number of vertices
int numVertices;
vertexString>>numVertices;
答案 0 :(得分:1)
将其添加到静态字符串实用程序类:
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;
}