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)將你的輸出行收集到一個字符串中並輸出當它完成時。 –