创建的默认qt小部件项目:
#include "mainwindow.h"
#include <string>
#include <cstring>
#include <QApplication>
#include <iostream>
#include <QDir>
int main(int argc, char *argv[])
{
std::string s = QDir::currentPath().toLocal8Bit().constData();
std::string s2 = QDir::currentPath().toLocal8Bit().constData();
std::string s3 = "dsdasda";
int t = s.size();
char str[1024]= { 0 };
char str2[1024]= { 0 };
std::memcpy(str,s.c_str(),s.size ());
std::memcpy(str2,&s,s.size ());
int i = 0;
while(str[i]) std::cout << str[i++] ;
char * pch;
pch = strtok (str,"/");
while (pch != NULL)
{
printf ("%s\n",pch);
pch = strtok (NULL, "/");
}
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
也是我的.pro文件:
QT += core gui network widgets
CONFIG += c++11
# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
mainwindow.cpp
HEADERS += \
mainwindow.h
FORMS += \
mainwindow.ui
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
仅由于其他文件是默认文件,所以不粘贴我的问题,因此粘贴了main.cpp。
这里是错误文本(或者可能是警告):
main.cpp:11:11: error: no type named 'string' in namespace 'std'
main.cpp:17:11: error: no member named 'memcpy' in namespace 'std'
main.cpp:3:10: error: 'cstring' file not found
和其他相同。
我不知道为什么会有这么多错误(警告?),如果有任何错误,为什么要编译并启动它,以及如何解决所有这些错误。
将其写入您的.pro文件:INCLUDEPATH += /usr/include/c++/{gcc_version}/