我已.clang-format
在项目中放置了一个文件,并且可以使用Ctrl+K, Ctrl+D
. 我还在 下配置并启用了“保存时运行代码清理配置文件” Options -> Text Editor -> Code Cleanup
。但是当我保存文件时,格式不会应用。
我有什么遗漏的吗?
先感谢您!
编辑:由于 C++ 似乎不可能(截至 2022 年 6 月),我现在将使用VS2022 的扩展“保存格式”,与 Sedenion 的建议相比,它具有更多功能。
我模仿我认为相当标准的Dialog
代码:
public class DChooseSeparator extends DialogFragment
{
// ...
@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
builder
.setTitle("My Title")
.setView(myDialogLayout)
.setPositiveButton(getString(R.string.sOKButton), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
if(myEditText.getText().toString().equals("")) // disable positive button if this is empty
{
Toast.makeText(getActivity(), "enter something!", Toast.LENGTH_SHORT).show();
}
else { myListener.onSet(myEditText.getText().toString()); }
}
})
.setNegativeButton(getString(R.string.sCancelButton), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// do nothing
}
});
return builder.create(); …
Run Code Online (Sandbox Code Playgroud) android android-fragments android-dialog android-dialogfragment
我想知道是否可以从我的 Java 代码中对 IntelliJ 运行控制台中的输出进行着色。例如,如果我有类似的东西
System.out.println("Error: " + message);
Run Code Online (Sandbox Code Playgroud)
我想将“错误”显示为红色,其余部分显示为不同的颜色。或者,整个系列作为一种颜色也很好,并且比所有东西都采用一种颜色已经是一个很大的改进。
先感谢您!
编辑:感谢一位好心的 redditor,答案是这里的链接Stack Overflow - ANSI 颜色转义序列列表 。
虽然我认为我还没有完全做到这一点(IntelliJ 提供了比我能够工作的更多的颜色选项),但我能够获得 8 种颜色来工作。我现在创建了一个小辅助函数,可以轻松地将文本打印到控制台:
public static void colorSystemOut(String text, Color color,
boolean bold, boolean underlined) {
StringBuilder cString = new StringBuilder("\033[");
if(color == Color.WHITE) {
cString.append("30");
}
else if(color == Color.RED) {
cString.append("31");
}
else if(color == Color.GREEN) {
cString.append("32");
}
else if(color == Color.YELLOW) {
cString.append("33");
}
else if(color == Color.BLUE) {
cString.append("34");
}
else if(color == Color.MAGENTA) { …
Run Code Online (Sandbox Code Playgroud) 我正在尝试了解const
VS2019constexpr
上的错误 C26498。但是,我的示例与此处描述的几乎相同:
constexpr int myInt();
constexpr int getMyValue();
void foo();
int main()
{
int val1 = myInt(); // C26498 warning (mark variable constexpr)
const int val2 = myInt(); // C26498 warning (mark variable constexpr)
constexpr int val3 = myInt(); // C2131 error (expression did not evaluate to a constant)
foo();
}
constexpr int myInt() { return 1; }
constexpr int getMyValue() { return 1; }
void foo() { constexpr int val0 = getMyValue(); // …
Run Code Online (Sandbox Code Playgroud) 假设我有以下程序将对象导出为 JSON:
\nstruct MyChronoObject {\n std::string name;\n std::chrono::system_clock::time_point birthday;\n\n MyChronoObject(const std::string name_) : name(name_) {\n birthday = std::chrono::system_clock::now();\n }\n\n std::string toJSON1() {\n std::string s = "{ \\"name\\": \\"" + name + "\\", \\"birthday\\": ";\n s += std::to_string((birthday.time_since_epoch().count() / 1000000));\n s += " }";\n return s;\n }\n\n std::string toJSON2() {\n std::string s = "{ \\"name\\": \\"" + name + "\\", \\"birthday\\": ";\n s += std::to_string((birthday.time_since_epoch().count()));\n s += " }";\n return s;\n }\n\n void setBirthday(int birthday_in_seconds) {\n // how do I …
Run Code Online (Sandbox Code Playgroud)