0
我试图用stdafx.h创建一个pascal三角形。 我来一个问题时,试图把一个Console::WriteLine(x)
使用一个循环,但在同一行当在CLR控制台中循环时使Console :: WriteLine(x)在同一行中C++
想它我“翻译”这从一个iostream的C++空项目
#include "stdafx.h"
using namespace System;
int main(array<System::String ^> ^args)
{
int k, i, x, a, b, c, d, e, f, g, h;
Console::WriteLine(L"Number of Rows : ");
String^ strabx = Console::ReadLine();
int n = int::Parse(strabx); //the number of rows
d = 0;
g = 0;
for (i = 0; i <= (n - 1); i++) // i adalah baris
{
for (a = (n - i); a >= 1; a--) {
Console::WriteLine(" ");
}
x = 1;
b = 0;
e = 0;
f = 0;
k = 0;
do
{
f = f + x;
Console::WriteLine(" " + x + " "); //my problem lies here
x = x * (i - k)/(k + 1);
b = b + 1;
k++;
} while (k <= i);
c = b;
d = d + c;
g = f + g;
Console::WriteLine();
}
Console::WriteLine("digit count " + d + "\n");
Console::WriteLine("sums of the number : " + g);
Console::ReadLine();
Console::WriteLine();
}
'stdafx.h'是为Visual Studio项目自动生成的预编译头的名称。它与产生帕斯卡三角形无关。我想也许你的意思是一个.NET项目。 –
无论如何,你有两个主要的选择:(1)使用像Console :: Write这样的例程,如果有的话(我想我记得有),或者(2)将你的输出行收集到一个字符串中并输出当它完成时。 –