控制台应用程序 - 返回一行并将文本添加到当前行

时间:2017-01-23 22:34:40

标签: console-application

我一直在寻找这个问题,但却没有找到如何去做的运气。

我想返回上一行,并向其中添加文字,例如,以下

E.g。 在某些Linux CentralManagerImpl::CentralManagerImpl() { _shim = ref new CentralManagerCppCxShim(this); _deviceWatcher = DeviceInformation::CreateWatcher(BluetoothLEDevice::GetDeviceSelectorFromPairingState(true)); _deviceWatcherAdded = _deviceWatcher->Added += ref new TypedEventHandler<DeviceWatcher ^, DeviceInformation ^>(_shim, &CentralManagerCppCxShim::OnDeviceAdded); _deviceWatcherRemoved = _deviceWatcher->Removed += ref new TypedEventHandler<DeviceWatcher ^, DeviceInformationUpdate ^>(_shim, &CentralManagerCppCxShim::OnDeviceRemoved); _deviceWatcherUpdated = _deviceWatcher->Updated += ref new TypedEventHandler<DeviceWatcher ^, DeviceInformationUpdate ^>(_shim, &CentralManagerCppCxShim::OnDeviceUpdated); _deviceWatcher->Stopped += ref new TypedEventHandler<DeviceWatcher ^, Object ^>(_shim, &CentralManagerCppCxShim::OnDeviceWatcherStopped); _watcher = ref new BluetoothLEAdvertisementWatcher(); BluetoothLEManufacturerData ^manufacturerData = ref new BluetoothLEManufacturerData(); manufacturerData->CompanyId = MAKEWORD(HIBYTE(OUR_COMPANY_IDENTIFIER), LOBYTE(OUR_COMPANY_IDENTIFIER)); _watcher->AdvertisementFilter->Advertisement->ManufacturerData->Append(manufacturerData); _watcher->Stopped += ref new TypedEventHandler<BluetoothLEAdvertisementWatcher ^, BluetoothLEAdvertisementWatcherStoppedEventArgs ^>(_shim, &CentralManagerCppCxShim::OnAdvertisementWatcherStopped); _watcherReceived = _watcher->Received += ref new TypedEventHandler<BluetoothLEAdvertisementWatcher ^, BluetoothLEAdvertisementReceivedEventArgs ^>(_shim, &CentralManagerCppCxShim::OnAdvertisementReceived); } CentralManagerImpl::~CentralManagerImpl() { _watcher->Received -= _watcherReceived; _watcher = nullptr; _deviceWatcher->Updated -= _deviceWatcherUpdated; _deviceWatcher->Removed -= _deviceWatcherRemoved; _deviceWatcher->Added -= _deviceWatcherAdded; _deviceWatcher = nullptr; // this crashes :( } void CentralManagerImpl::StartScan() { _deviceWatcher->Start(); _watcher->Start(); } void CentralManagerImpl::StopScan() { _watcher->Stop(); _deviceWatcher->Stop(); } 上运行ntdll.dll!_TppRaiseInvalidParameter@0() ntdll.dll!_TpPostWork@4() cfgmgr32.dll!TQuery::CloseQuery() cfgmgr32.dll!_DevCloseObjectQuery@4() Windows.Devices.Enumeration.dll!Watcher<class Windows::Devices::Enumeration::DeviceWatcher,struct Windows::Devices::Enumeration::IDeviceWatcher,struct Windows::Devices::Enumeration::IDeviceWatcher2,class Windows::Devices::Enumeration::DeviceInformation,struct Windows::Devices::Enumeration::IDeviceInformation,struct Windows::Devices::Enumeration::IDeviceInformation2,class DeviceInformationServer,class Windows::Devices::Enumeration::DeviceInformationUpdate,struct Windows::Devices::Enumeration::IDeviceInformationUpdate,class DeviceInformationUpdateServer,&unsigned short const * const RuntimeClass_Windows_Devices_Enumeration_DeviceWatcher>::Impl::EndQuery(void) Windows.Devices.Enumeration.dll!Watcher<class Windows::Devices::Enumeration::DeviceWatcher,struct Windows::Devices::Enumeration::IDeviceWatcher,struct Windows::Devices::Enumeration::IDeviceWatcher2,class Windows::Devices::Enumeration::DeviceInformation,struct Windows::Devices::Enumeration::IDeviceInformation,struct Windows::Devices::Enumeration::IDeviceInformation2,class DeviceInformationServer,class Windows::Devices::Enumeration::DeviceInformationUpdate,struct Windows::Devices::Enumeration::IDeviceInformationUpdate,class DeviceInformationUpdateServer,&unsigned short const * const RuntimeClass_Windows_Devices_Enumeration_DeviceWatcher>::Impl::Stop(bool) Windows.Devices.Enumeration.dll!Watcher<class Windows::Devices::Enumeration::DeviceWatcher,struct Windows::Devices::Enumeration::IDeviceWatcher,struct Windows::Devices::Enumeration::IDeviceWatcher2,class Windows::Devices::Enumeration::DeviceInformation,struct Windows::Devices::Enumeration::IDeviceInformation,struct Windows::Devices::Enumeration::IDeviceInformation2,class DeviceInformationServer,class Windows::Devices::Enumeration::DeviceInformationUpdate,struct Windows::Devices::Enumeration::IDeviceInformationUpdate,class DeviceInformationUpdateServer,&unsigned short const * const RuntimeClass_Windows_Devices_Enumeration_DeviceWatcher>::~Watcher<class Windows::Devices::Enumeration::DeviceWatcher,struct Windows::Devices::Enumeration::IDeviceWatcher,struct Windows::Devices::Enumeration::IDeviceWatcher2,class Windows::Devices::Enumeration::DeviceInformation,struct Windows::Devices::Enumeration::IDeviceInformation,struct Windows::Devices::Enumeration::IDeviceInformation2,class DeviceInformationServer,class Windows::Devices::Enumeration::Devic() Windows.Devices.Enumeration.dll!Watcher<class Windows::Devices::Enumeration::DeviceWatcher,struct Windows::Devices::Enumeration::IDeviceWatcher,struct Windows::Devices::Enumeration::IDeviceWatcher2,class Windows::Devices::Enumeration::DeviceInformation,struct Windows::Devices::Enumeration::IDeviceInformation,struct Windows::Devices::Enumeration::IDeviceInformation2,class DeviceInformationServer,class Windows::Devices::Enumeration::DeviceInformationUpdate,struct Windows::Devices::Enumeration::IDeviceInformationUpdate,class DeviceInformationUpdateServer,&unsigned short const * const RuntimeClass_Windows_Devices_Enumeration_DeviceWatcher>::`vector deleting destructor'(unsigned int) Windows.Devices.Enumeration.dll!Microsoft::WRL::Details::RuntimeClass<struct Microsoft::WRL::Details::InterfaceList<struct Windows::Devices::Enumeration::IDeviceWatcher,struct Microsoft::WRL::Details::InterfaceList<struct Windows::Devices::Enumeration::IDeviceWatcher2,struct Microsoft::WRL::Details::InterfaceList<struct Windows::Foundation::IClosable,struct Microsoft::WRL::Details::InterfaceList<class Microsoft::WRL::FtmBase,class Microsoft::WRL::Details::Nil> > > >,struct Microsoft::WRL::RuntimeClassFlags<3>,1,1,0>::Release(void) mydll.dll!__abi_winrt_ptr_assign(void * * __ppTargetArg, const volatile Platform::Object ^ __objArg) Line 405 mydll.dll!CentralManagerImpl::~CentralManagerImpl() Line 64 [External Code] //… 时,我注意到以下内容:

make

这将通过类似的&amp;基本的伪代码概念(据我所知和理解)。

makefile

这将输出:

  

检查:{fileName} ........

     

完成

有没有办法可以在椭圆后添加完成?

我记得在ncurses和其他一些libs上读过一些东西,但我更愿意,如果这可以纯粹使用Qt来完成

提前致谢

2 个答案:

答案 0 :(得分:1)

我认为这不可能在经典的控制台应用程序中完成。控制台只是一个流,你不能回去改变东西,做了什么。如果要表示更新,请输出与更新相同的行。

或者,如果你想要做的只是在同一行有done,那就跳过上一个std::endl。然后就没有必要回去了。

答案 1 :(得分:0)

这不是通过备份线来完成的。相反,该行的初始部分是在没有换行符的情况下输出的,然后当&#34;完成&#34;打印部分,它继续在当前行。这实际上不是Qt问题;你的示例代码是没有任何Qt的纯C ++,但你需要做的就是删除&#34; std :: endl&#34;从打印的行&#34;检查:&#34;。