ROS2 in 5 Days C++ ERROR in Unit 5

I am getting this error when I want to echo the /counter topic

Same error pops up when I want to pub on the topic. Any idea what that might be?

Try with:
ros2 topic echo /counter std_msgs/Int32

And verify that the topic is available:
ros2 topic list

Found the issue, just needed to use a terminal with the /opt/ros/foxy/setup.bash sourced instead of the ros2_ws setup file sourced. Not sure if this was the root cause of the issue but works now.

thanks @mtorres for chipping in. Found the solution now.