0
我有以下問題:C++終端輸出不生產新行
我的C++代碼如下所示。
int main()
{
std::string String;
int rows = 0;
int cols = 0;
std::getline (std::cin,String);
std::cin >> rows;
std::cin >> cols;
std::cout << "Enter a fancy string: " << String << std::endl;
std::cout << "Enter the number of rows: " << rows << std::endl;
std::cout << "Enter the number of cols: " << cols << std::endl;
std::string ArrayofStrings;
for(int x = 0; x<rows; x++){
ArrayofStrings = "";
for (int y = 0; y < cols; y++) {
ArrayofStrings += String;
}
std::cout << ArrayofStrings << std::endl; }
// std::cout << std::endl;
return 0;
}
總之,它讀取字符串,並打印出給定的字符串與規定尺寸的陣列。但是,當我linux的終端上運行,輸出看起來是這樣的:
Enter a fancy string: 4
Enter the number of rows: 5
Enter the number of columns: 5
44444
44444
44444
44444
44444[[email protected]] (3)$
但我不能作出這樣的[enkhtaiv @皇家-10]從線Linux文本開始不管。我試過std::endl, "\n"
,但他們似乎沒有工作。
令人困惑的是,這個程序在IDE上工作得很好,但是當我在Linux終端上編譯並運行它時,這個問題仍然存在。 我是C++和linux的初學者,所以如果這是一個完全無關緊要的問題,我會提前道歉。