为什么在这个输出的最后有一个尾部的%? 我试过刷新流(不是endl),但是当我用调用endl结束流时,它就把%去掉了。 如果有任何帮助,我将非常感激。
template<class T>
void print_collection(T * t){
for(int i = 0; i < t->size()-1; ++i){
cout << t->at(i) << ", ";
}
std::cout<< t->at(t->size() -1);
std::cout<<flush;
}
int main(){
int n_A = 5;
int A[] = {2, 3, -2, 34, -29};
vector<int> vec(A, A + n_A);
sort(vec.begin(), vec.end());
print_collection(&vec);
return 0;
}
OUTPUT
-29, -2, 2, 3, 34%
这里有更多关于编译器的信息,我使用的是macOS 10.15.4。
g++ -Wall -std=c++11 array.cpp -o array
g++ Information:
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 11.0.3 (clang-1103.0.32.59)
Target: x86_64-apple-darwin19.4.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
重复的问题。 谢谢 @WBuck!
@Kevin说:当一个程序的(非空)输出没有包含尾部的换行符时,zsh会添加那个颜色反转的%来表示,并在打印提示符之前移动到下一行;它通常比bash的行为更方便,只是在输出结束的地方开始命令提示符。