diff --git a/cscore/examples/httpcvstream/httpcvstream.cpp b/cscore/examples/httpcvstream/httpcvstream.cpp index 61c3d1625e..38a00dbbf9 100644 --- a/cscore/examples/httpcvstream/httpcvstream.cpp +++ b/cscore/examples/httpcvstream/httpcvstream.cpp @@ -3,8 +3,8 @@ // the WPILib BSD license file in the root directory of this project. #include -#include +#include #include #include "cscore.h" @@ -24,11 +24,11 @@ int main() { for (;;) { uint64_t time = cvsink.GrabFrame(test); if (time == 0) { - std::cout << "error: " << cvsink.GetError() << std::endl; + fmt::print("error: {}\n", cvsink.GetError()); continue; } - std::cout << "got frame at time " << time << " size " << test.size() - << std::endl; + fmt::print("got frame at time {} size ({}, {})\n", time, test.size().width, + test.size().height); cv::flip(test, flip, 0); cvsource.PutFrame(flip); } diff --git a/cscore/examples/usbcvstream/usbcvstream.cpp b/cscore/examples/usbcvstream/usbcvstream.cpp index dcb024d345..3635221abc 100644 --- a/cscore/examples/usbcvstream/usbcvstream.cpp +++ b/cscore/examples/usbcvstream/usbcvstream.cpp @@ -2,9 +2,7 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. -#include -#include - +#include #include #include "cscore.h" @@ -26,11 +24,11 @@ int main() { for (;;) { uint64_t time = cvsink.GrabFrame(test); if (time == 0) { - std::cout << "error: " << cvsink.GetError() << std::endl; + fmt::print("error: {}\n", cvsink.GetError()); continue; } - std::cout << "got frame at time " << time << " size " << test.size() - << std::endl; + fmt::print("got frame at time {} size ({}, {})\n", time, test.size().width, + test.size().height); cv::flip(test, flip, 0); cvsource.PutFrame(flip); } diff --git a/cscore/src/dev/native/cpp/main.cpp b/cscore/src/dev/native/cpp/main.cpp index af366144f8..279d72a5e8 100644 --- a/cscore/src/dev/native/cpp/main.cpp +++ b/cscore/src/dev/native/cpp/main.cpp @@ -2,10 +2,10 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. -#include +#include #include "cscore.h" int main() { - std::cout << cs::GetHostname() << std::endl; + fmt::print("{}\n", cs::GetHostname()); } diff --git a/hal/src/dev/native/cpp/main.cpp b/hal/src/dev/native/cpp/main.cpp index d31456237e..721c0f65d0 100644 --- a/hal/src/dev/native/cpp/main.cpp +++ b/hal/src/dev/native/cpp/main.cpp @@ -2,11 +2,11 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. -#include +#include #include "hal/HAL.h" int main() { - std::cout << "Hello World" << std::endl; - std::cout << HAL_GetRuntimeType() << std::endl; + fmt::print("Hello World\n"); + fmt::print("{}\n", HAL_GetRuntimeType()); } diff --git a/ntcore/manualTests/native/rpc_speed.cpp b/ntcore/manualTests/native/rpc_speed.cpp index 169729f679..6f9dbbf7a3 100644 --- a/ntcore/manualTests/native/rpc_speed.cpp +++ b/ntcore/manualTests/native/rpc_speed.cpp @@ -4,10 +4,9 @@ #include #include -#include -#include #include +#include #include #include "ntcore.h" @@ -17,11 +16,11 @@ void callback1(const nt::RpcAnswer& answer) { try { params = wpi::json::from_cbor(answer.params); } catch (wpi::json::parse_error err) { - std::fputs("could not decode params?\n", stderr); + fmt::print(stderr, "could not decode params?\n"); return; } if (!params.is_number()) { - std::fputs("did not get number\n", stderr); + fmt::print(stderr, "did not get number\n"); return; } double val = params.get(); @@ -44,29 +43,25 @@ int main() { try { call1_result = wpi::json::from_cbor(call1_result_str); } catch (wpi::json::parse_error err) { - std::fputs("could not decode result?\n", stderr); + fmt::print(stderr, "could not decode result?\n"); return 1; } if (!call1_result.is_number()) { - std::fputs("result is not number?\n", stderr); + fmt::print(stderr, "result is not number?\n"); return 1; } } auto end2 = std::chrono::high_resolution_clock::now(); auto end = nt::Now(); - std::cerr << "nt::Now start=" << start << " end=" << end << '\n'; - std::cerr << "std::chrono start=" - << std::chrono::duration_cast( - start2.time_since_epoch()) - .count() - << " end=" - << std::chrono::duration_cast( - end2.time_since_epoch()) - .count() - << '\n'; - std::fprintf(stderr, "time/call = %g us\n", (end - start) / 10.0 / 10000.0); + fmt::print(stderr, "nt::Now start={} end={}\n", start, end); + fmt::print(stderr, "std::chrono start={} end={}\n", + std::chrono::duration_cast( + start2.time_since_epoch()) + .count(), + std::chrono::duration_cast( + end2.time_since_epoch()) + .count()); + fmt::print(stderr, "time/call = %g us\n", (end - start) / 10.0 / 10000.0); std::chrono::duration diff = end2 - start2; - std::cerr << "time/call = " << (diff.count() / 10000.0) << " us\n"; - - return 0; + fmt::print(stderr, "time/call = {} us\n", diff.count() / 10000.0); } diff --git a/ntcore/src/dev/native/cpp/main.cpp b/ntcore/src/dev/native/cpp/main.cpp index ba692eb749..f86301867a 100644 --- a/ntcore/src/dev/native/cpp/main.cpp +++ b/ntcore/src/dev/native/cpp/main.cpp @@ -2,7 +2,7 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. -#include +#include #include "ntcore.h" @@ -11,5 +11,5 @@ int main() { nt::SetEntryValue(myValue, nt::Value::MakeString("Hello World")); - std::cout << nt::GetEntryValue(myValue)->GetString() << std::endl; + fmt::print("{}\n", nt::GetEntryValue(myValue)->GetString()); } diff --git a/simulation/halsim_gazebo/src/main/native/cpp/main.cpp b/simulation/halsim_gazebo/src/main/native/cpp/main.cpp index 752e7c6a6b..a3d0576521 100644 --- a/simulation/halsim_gazebo/src/main/native/cpp/main.cpp +++ b/simulation/halsim_gazebo/src/main/native/cpp/main.cpp @@ -2,8 +2,7 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. -#include - +#include #include #include "GazeboAnalogIn.h" @@ -19,14 +18,14 @@ static HALSimGazebo halsim; extern "C" { int HALSIM_InitExtension(void) { - std::cout << "Gazebo Simulator Initializing." << std::endl; + fmt::print("Gazebo Simulator Initializing.\n"); if (!halsim.node.Connect()) { - std::cerr << "Error: unable to connect to Gazebo. Is it running?." - << std::endl; + fmt::print(stderr, + "Error: unable to connect to Gazebo. Is it running?.\n"); return -1; } - std::cout << "Gazebo Simulator Connected." << std::endl; + fmt::print("Gazebo Simulator Connected.\n"); for (int i = 0; i < HALSimGazebo::kPWMCount; i++) halsim.pwms[i] = new GazeboPWM(i, &halsim); diff --git a/simulation/halsim_ws_client/src/dev/native/cpp/main.cpp b/simulation/halsim_ws_client/src/dev/native/cpp/main.cpp index 030a930d75..cf32a3fd95 100644 --- a/simulation/halsim_ws_client/src/dev/native/cpp/main.cpp +++ b/simulation/halsim_ws_client/src/dev/native/cpp/main.cpp @@ -2,9 +2,9 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. -#include #include +#include #include #include #include @@ -21,9 +21,9 @@ int main() { while (cycleCount < 100) { std::this_thread::sleep_for(std::chrono::milliseconds(100)); cycleCount++; - std::cout << "Count: " << cycleCount << std::endl; + fmt::print("Count: {}\n", cycleCount); } - std::cout << "DONE" << std::endl; + fmt::print("DONE\n"); HAL_ExitMain(); } diff --git a/wpilibc/src/dev/native/cpp/main.cpp b/wpilibc/src/dev/native/cpp/main.cpp index 54bf102cf3..28fac9d77b 100644 --- a/wpilibc/src/dev/native/cpp/main.cpp +++ b/wpilibc/src/dev/native/cpp/main.cpp @@ -2,15 +2,13 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. -#include - +#include #include #include "WPILibVersion.h" int main() { - std::cout << "Hello World" << std::endl; - std::cout << HAL_GetRuntimeType() << std::endl; - std::cout << GetWPILibVersion() << std::endl; - return 0; + fmt::print("Hello World\n"); + fmt::print("{}\n", HAL_GetRuntimeType()); + fmt::print("{}\n", GetWPILibVersion()); } diff --git a/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/Robot.cpp index 87b3dbd435..a679268094 100644 --- a/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/examples/PacGoat/cpp/Robot.cpp @@ -4,7 +4,7 @@ #include "Robot.h" -#include +#include #include #include @@ -53,7 +53,7 @@ void Robot::TeleopInit() { if (m_autonomousCommand != nullptr) { m_autonomousCommand->Cancel(); } - std::cout << "Starting Teleop" << std::endl; + fmt::print("Starting Teleop\n"); } void Robot::TeleopPeriodic() { diff --git a/wpilibcExamples/src/main/cpp/templates/timed/cpp/Robot.cpp b/wpilibcExamples/src/main/cpp/templates/timed/cpp/Robot.cpp index 6c04fbc9b4..577de89da1 100644 --- a/wpilibcExamples/src/main/cpp/templates/timed/cpp/Robot.cpp +++ b/wpilibcExamples/src/main/cpp/templates/timed/cpp/Robot.cpp @@ -4,7 +4,7 @@ #include "Robot.h" -#include +#include #include @@ -39,7 +39,7 @@ void Robot::AutonomousInit() { m_autoSelected = m_chooser.GetSelected(); // m_autoSelected = SmartDashboard::GetString("Auto Selector", // kAutoNameDefault); - std::cout << "Auto selected: " << m_autoSelected << std::endl; + fmt::print("Auto selected: {}\n", m_autoSelected); if (m_autoSelected == kAutoNameCustom) { // Custom Auto goes here diff --git a/wpimath/src/dev/native/cpp/main.cpp b/wpimath/src/dev/native/cpp/main.cpp index 85398058e9..54952b7188 100644 --- a/wpimath/src/dev/native/cpp/main.cpp +++ b/wpimath/src/dev/native/cpp/main.cpp @@ -2,10 +2,9 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. -#include - +#include #include int main() { - std::cout << wpi::numbers::pi << std::endl; + fmt::print("{}\n", wpi::numbers::pi); } diff --git a/wpiutil/src/dev/native/cpp/main.cpp b/wpiutil/src/dev/native/cpp/main.cpp index ede6910134..14ddda296c 100644 --- a/wpiutil/src/dev/native/cpp/main.cpp +++ b/wpiutil/src/dev/native/cpp/main.cpp @@ -2,12 +2,10 @@ // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. -#include - +#include "fmt/core.h" #include "wpi/SmallString.h" -#include "wpi/hostname.h" int main() { wpi::SmallString<128> v1("Hello"); - std::cout << v1.str() << std::endl; + fmt::print("{}\n", v1.str()); } diff --git a/wpiutil/src/test/native/cpp/spinlock_bench.cpp b/wpiutil/src/test/native/cpp/spinlock_bench.cpp index f1199fccb6..953483755d 100644 --- a/wpiutil/src/test/native/cpp/spinlock_bench.cpp +++ b/wpiutil/src/test/native/cpp/spinlock_bench.cpp @@ -5,10 +5,10 @@ #include "wpi/spinlock.h" // NOLINT(build/include_order) #include -#include #include #include +#include "fmt/core.h" #include "gtest/gtest.h" #include "wpi/mutex.h" @@ -50,9 +50,8 @@ TEST(SpinlockTest, Benchmark) { ++value; } auto stop = high_resolution_clock::now(); - std::cout << "std::mutex sizeof: " << sizeof(std_mutex) - << " time: " << duration_cast(stop - start).count() - << " value: " << value << "\n"; + fmt::print("std::mutex sizeof: {} time: {} value: {}\n", sizeof(std_mutex), + duration_cast(stop - start).count(), value); }); thrb.join(); @@ -65,9 +64,9 @@ TEST(SpinlockTest, Benchmark) { ++value; } auto stop = high_resolution_clock::now(); - std::cout << "std::recursive_mutex sizeof: " << sizeof(std_recursive_mutex) - << " time: " << duration_cast(stop - start).count() - << " value: " << value << "\n"; + fmt::print("std::recursive_mutex sizeof: {} time: {} value: {}\n", + sizeof(std_recursive_mutex), + duration_cast(stop - start).count(), value); }); thrb2.join(); @@ -80,9 +79,8 @@ TEST(SpinlockTest, Benchmark) { ++value; } auto stop = high_resolution_clock::now(); - std::cout << "wpi::mutex sizeof: " << sizeof(wpi_mutex) - << " time: " << duration_cast(stop - start).count() - << " value: " << value << "\n"; + fmt::print("wpi::mutex sizeof: {} time: {} value: {}\n", sizeof(wpi_mutex), + duration_cast(stop - start).count(), value); }); thr2.join(); @@ -95,9 +93,9 @@ TEST(SpinlockTest, Benchmark) { ++value; } auto stop = high_resolution_clock::now(); - std::cout << "wpi::recursive_mutex sizeof: " << sizeof(wpi_recursive_mutex) - << " time: " << duration_cast(stop - start).count() - << " value: " << value << "\n"; + fmt::print("wpi::recursive_mutex sizeof: {} time: {} value: {}\n", + sizeof(wpi_recursive_mutex), + duration_cast(stop - start).count(), value); }); thr2b.join(); @@ -110,9 +108,8 @@ TEST(SpinlockTest, Benchmark) { ++value; } auto stop = high_resolution_clock::now(); - std::cout << "spinlock sizeof: " << sizeof(spinlock) - << " time: " << duration_cast(stop - start).count() - << " value: " << value << "\n"; + fmt::print("spinlock sizeof: {} time: {} value: {}\n", sizeof(spinlock), + duration_cast(stop - start).count(), value); }); thr3.join(); @@ -125,9 +122,9 @@ TEST(SpinlockTest, Benchmark) { ++value; } auto stop = high_resolution_clock::now(); - std::cout << "recursive_spinlock1 sizeof: " << sizeof(recursive_spinlock1) - << " time: " << duration_cast(stop - start).count() - << " value: " << value << "\n"; + fmt::print("recursive_spinlock1 sizeof: {} time: {} value: {}\n", + sizeof(recursive_spinlock1), + duration_cast(stop - start).count(), value); }); thr4.join(); @@ -140,9 +137,9 @@ TEST(SpinlockTest, Benchmark) { ++value; } auto stop = high_resolution_clock::now(); - std::cout << "recursive_spinlock2 sizeof: " << sizeof(recursive_spinlock2) - << " time: " << duration_cast(stop - start).count() - << " value: " << value << "\n"; + fmt::print("recursive_spinlock2 sizeof: {} time: {} value: {}\n", + sizeof(recursive_spinlock2), + duration_cast(stop - start).count(), value); }); thr4b.join(); @@ -155,9 +152,9 @@ TEST(SpinlockTest, Benchmark) { ++value; } auto stop = high_resolution_clock::now(); - std::cout << "recursive_spinlock sizeof: " << sizeof(recursive_spinlock) - << " time: " << duration_cast(stop - start).count() - << " value: " << value << "\n"; + fmt::print("recursive_spinlock sizeof: {} time: {} value: {}\n", + sizeof(recursive_spinlock), + duration_cast(stop - start).count(), value); }); thr4c.join(); }