编译错误在c++中使用Linux程序制作
Compile error in C++ using Linux program make
我目前正在尝试将这部分代码从C移植到c++。它基本上将snprintf语句替换为c++实现。
if (len > 0) // If statement for 0 length buf error
{
localTime(tv, &etime2);
// Printing to the supplied buffer in the main program
char timebuf[80]; // Buffer to hold the time stamp
oststream oss(timebuf, sizeof(timebuf));
oss << etime2.et_year << ends;
cout << timebuf << endl;
// snprintf(buf, len, "%02i %s %02i %02i:%02i:%02i:%03i",
// etime2.et_year, month[etime2.et_mon], etime2.et_day, etime2.et_hour,
// etime2.et_min, etime2.et_sec, etime2.et_usec);
我已经注释掉了原来的snprintf
,所以我有它作为参考。我需要使用cout
, OSS和oststream
打印确切的字符串。我已经包含了适当的头文件iostream
、strsteam
和"使用命名空间std;"。但是,当我使用"make"运行它时,我得到以下错误
g++ -g -Wno-deprecated -c fmttime.cc fmttime.o
fmttime.cc:14:22: error: strsteam.h: No such file or directory
fmttime.cc:15:21: error: iosteam.h: No such file or directory
fmttime.cc: In function 'char* formatTime(timeval*, char*, size_t)':
fmttime.cc:273: error: 'oststream' was not declared in this scope
fmttime.cc:273: error: expected ';' before 'oss'
fmttime.cc:275: error: 'oss' was not declared in this scope
fmttime.cc:275: error: 'ends' was not declared in this scope
fmttime.cc:276: error: 'cout' was not declared in this scope
fmttime.cc:276: error: 'endl' was not declared in this scope
make: *** [fmttime.o] Error 1
这是我的制作文件供参考。
#Variables
PROGRAM = plot
OBJS = plot.o fmttime.o
CXXFLAGS = -g -Wno-deprecated
LIBS = -lm -lcurses
#Rules
all : ${PROGRAM}
${PROGRAM} : ${OBJS}
g++ ${OBJS} ${LIBS} -o ${PROGRAM}
%.o : %.cc
g++ ${CXXFLAGS} -c $< $@
clean:
rm ${OBJS} ${PROGRAM}
所以我一直在尝试一切,我包括头后的。h,但我知道在c++中这是不必要的。我不明白为什么它告诉我iostream
和strstream
超出了范围…
您使用了已弃用(且拼写错误)的标头。
使用<sstream>
和<iostream>
代替
你有打字错误:
oststream //^^typo
你需要包含正确的头文件:
#include <iostream>
#include <sstream> //not strstream, deprecated
使用正确的命名空间std:
std::cout;
std::endl;
相关文章:
- 在VS代码中交叉编译Windows与Linux上的MinGW的SDL程序
- 在Linux下捕获SIGKILL的C++程序
- 在不使用系统的情况下从C++应用程序格式化 Linux 中的 SD 卡
- 网站和C++程序在同一台 Linux PC 上的通信
- 如何检查第三个 API 是否在 Linux 中为 c/c++ 程序创建了一个新线程?
- 旧的 32 位 Linux 程序最终如何调用 64 位库
- 可以在linux程序中使用msvc在windows上构建的boost lib吗
- C 从内部程序代码上将应用程序添加到Linux程序上的启动中
- 在窗口中执行 Linux c++ 程序
- c程序的Linux程序,以获取非根源用户的设备序列号
- 新的Linux程序员 - 尝试开发库
- Linux C++程序以一个仍在运行的线程结束后该怎么办
- Linux C 程序使用用 C/C++ 编写的共享库
- Linux C++程序通过系统调用启动bash脚本时总是返回-1
- 通过多用户网页重复执行linux程序而不会崩溃
- 如何使用Eclipse从Windows调试linux C++程序
- 构造一个c++linux程序.何时分解单独的文件与单独的程序
- 如何在linux程序和windows程序之间通过Wine(同一台计算机)共享内存
- 编译错误在c++中使用Linux程序制作
- 从C#中的Windows.NET程序到C++中的Linux程序之间的TCP