Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/131.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ Zebra打印机TTP 2030不工作_C++_Printing_Ofstream_Zebra Printers - Fatal编程技术网

C++ Zebra打印机TTP 2030不工作

C++ Zebra打印机TTP 2030不工作,c++,printing,ofstream,zebra-printers,C++,Printing,Ofstream,Zebra Printers,我正在用斑马打印机TTP2030打印“Hello World” std::ofstream of; of.open("Zebra TTP 2030"); if (of.is_open()) { debug(std::string("open : ok")); of << ticket.generateCode(); // return std::string // ^XA^FO50,50^ADN,10,10^F

我正在用斑马打印机TTP2030打印“Hello World”

std::ofstream of;

of.open("Zebra TTP 2030");
if (of.is_open())
{
  debug(std::string("open : ok"));

  of << ticket.generateCode(); // return std::string
                               // ^XA^FO50,50^ADN,10,10^FDHello World^FS^XZ
  of.flush();
  of.close();
}
else 
  debug(std::string("open : ko"));
std::的流;
开放式(“Zebra TTP 2030”);
如果(of.is_open())
{
调试(标准::字符串(“打开:确定”);

当然,您已经创建了一个名为“Zebra TTP 2030”的文本文件,您的文本就在其中


C++没有将输出发送到打印机的标准方法-您必须查阅Microsoft帮助以了解其操作方式。

从命令行打印内容的方法是使用
print

因此,您可以通过从应用程序中调用
print
来实现您的要求

#include<fstream>
#include<string>
#include<cstdlib>

void print_to_file(string filename){
    std::ofstream printer(filename);
    printer<<"Hello";
}

//create file with contents to print
int main(){
    std::string filename("print_this.tmp");
    print_to_file(filename);
    std::string command("print \\d:\\\\ServerName\\PrinterName ");
    std::system(command + filename);
}
#包括
#包括
#包括
无效打印到文件(字符串文件名){
std::流式打印机(文件名);

打印机您是否尝试了.open(“PRN:”);
?@CaptainGiraffe它不工作。我的Zebra打印机连接到USB端口。我在终端中尝试了此操作:“无法初始化设备\\USB001\\TTP2030”USB001不是您的计算机名。我想您可以在打印机设置中找到它。或者在这里运行
net user
@Gura More,这很有效。但是我必须做一个小动作,我的Zebra打印机使用USB001端口。因此我必须:右键单击打印机,属性>端口*选中启用打印机池。*选择端口LPT1。然后,以下代码
系统(“print/d:lpt1 test.tmp”)
工作