I’m new to C++ and have had some help with my program to compare two XML files. This is the code I have:
#include "pugixml.hpp"
#include <iostream>
#include <unordered_map>
int main() {
pugi::xml_document doca, docb;
std::map<string, pugi::xml_node> mapa, mapb;
if (!doca.load_file("a.xml") || !docb.load_file("b.xml"))
return 1;
for (auto& node: doca.child("site_entries").children("entry")) {
const char* id = node.child_value("id");
mapa[new std::string(id, strlen(id))] = node;
}
for (auto& node: docb.child("site_entries").children("entry"))
const char* idcs = node.child_value("id");
std::string id = new std::string(idcs, strlen(idcs));
if (!mapa.erase(id)) {
mapb[id] = node;
}
}
}
I seem to get a lot of errors when I try and compile it.
The first one I get is this:
src/main.cpp:10:14: error: unknown type name 'string'; did you mean 'std::string'?
std::map<string, pugi::xml_node> mapa, mapb;
~~~~~^~~
From what I understand, I have specified it correctly. Should I change it as it requests or is something else a-miss?
I’m new to C++ and have had some help with my program to compare two XML files. This is the code I have:
#include "pugixml.hpp"
#include <iostream>
#include <unordered_map>
int main() {
pugi::xml_document doca, docb;
std::map<string, pugi::xml_node> mapa, mapb;
if (!doca.load_file("a.xml") || !docb.load_file("b.xml"))
return 1;
for (auto& node: doca.child("site_entries").children("entry")) {
const char* id = node.child_value("id");
mapa[new std::string(id, strlen(id))] = node;
}
for (auto& node: docb.child("site_entries").children("entry"))
const char* idcs = node.child_value("id");
std::string id = new std::string(idcs, strlen(idcs));
if (!mapa.erase(id)) {
mapb[id] = node;
}
}
}
I seem to get a lot of errors when I try and compile it.
The first one I get is this:
src/main.cpp:10:14: error: unknown type name 'string'; did you mean 'std::string'?
std::map<string, pugi::xml_node> mapa, mapb;
~~~~~^~~
From what I understand, I have specified it correctly. Should I change it as it requests or is something else a-miss?
I’m working on a C++ header file and I keep getting the error «Unknown type name ‘string’; did you mean ‘std::string’?» #include <string>
is already at the top of my code, so I’m not sure how else to remedy this issue. Any thoughts? I’m using Xcode, if that makes any difference.
#ifndef POINT_HPP
#define POINT_HPP
#include <string>
using namespace std;
class Point {
public:
Point();
Point(int pInitX, int pInitY);
Point(int pInitX, int pInitY, int pInitColor);
double distance(Point pAnotherPoint);
int getColor();
int getX();
int getY();
void move(int pNewX, int pNewY);
void setColor(int pNewColor);
void setX(int pNewX);
void setY(int pNewY);
string toString; // Error: Unknown type name 'string'; did you mean 'std::string'?
private:
void init(int pInitX, int pInitY, int pInitColor);
int mColor;
int mX;
int mY;
};
#endif
asked Apr 3, 2016 at 1:52
5
you must use std::string toString()
or declare using namespace std;
globally
answered Apr 3, 2016 at 2:53
DanielDaniel
661 silver badge9 bronze badges
Make sure to also set the path to the Point
class (header and cpp) inside CMakeLists.txt
.
If you are using QT, it should be something like
set(PROJECT_SOURCES
...
point.cpp
point.h
)
After that you need to import the string class at the top like this #include <string>
and then declare using namespace std;
answered Oct 18, 2021 at 10:06
Forum
- Beginners
- Windows Programming
- UNIX/Linux Programming
- General C++ Programming
- Lounge
- Jobs
- Forum
- Beginners
- Unknown type name ‘string’
Unknown type name ‘string’
I’m trying to compile my code .cpp but even though I include the libraries I get those errors:
error: unknown type name
‘string’
static string* split(string s);
|
|
For instance, the MakeFile is as follows:
|
|
Why am I getting those errors? Thanks!
Did you include <string> in KingSort.h?
Oh I didn’t! Thanks!
Topic archived. No new replies allowed.
Information:Gradle tasks [:assembleArm7Debug]
Warning:Dependency org.json:json:20090211 is ignored for arm7Debug as it may be conflicting with the internal version provided by Android.
Warning:Dependency org.json:json:20090211 is ignored for arm7Release as it may be conflicting with the internal version provided by Android.
Warning:Dependency org.json:json:20090211 is ignored for x86Debug as it may be conflicting with the internal version provided by Android.
Warning:Dependency org.json:json:20090211 is ignored for x86Release as it may be conflicting with the internal version provided by Android.
/Users/chenhongyu/code/android-ndk-r10e/platforms/android-19/arch-arm/usr/include/jni.h
Information:(78, 25) ‘jstring’ declared here
/Users/chenhongyu/code/openFrameworks-master/addons/ofxAndroid/src/ofxAndroidVideoPlayer.h
Error:(23, 13) error: unknown type name ‘string’; did you mean ‘jstring’?
Warning:(23, warning: ‘ofxAndroidVideoPlayer::load’ hides overloaded virtual function [-Woverloaded-virtual]
/Users/chenhongyu/code/openFrameworks-master/libs/openFrameworks/video/ofVideoPlayer.cpp
Information:(26, 18) in instantiation of function template specialization ‘std::__1::make_shared’ requested here
/Users/chenhongyu/code/openFrameworks-master/libs/openFrameworks/types/ofBaseTypes.h
Information:(467, 21) hidden overloaded virtual function ‘ofBaseVideoPlayer::load’ declared here: type mismatch at 1st parameter (‘std::string’ (aka ‘basic_string<char, char_traits, allocator >’) vs ‘jstring’ (aka ‘_jstring *’))
Information:(467, 21) unimplemented pure virtual method ‘load’ in ‘ofxAndroidVideoPlayer’
/Users/chenhongyu/code/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libcxx/include/memory
Error:(2035, 9) error: field type ‘ofxAndroidVideoPlayer’ is an abstract class
Information:(2302, 15) in instantiation of template class ‘std::__1::__libcpp_compressed_pair_imp<std::__1::allocator, ofxAndroidVideoPlayer, 1>’ requested here
Information:(3689, 36) in instantiation of template class ‘std::__1::__compressed_pair<std::__1::allocator, ofxAndroidVideoPlayer>’ requested here
Information:(4271, 26) in instantiation of template class ‘std::__1::__shared_ptr_emplace<ofxAndroidVideoPlayer, std::__1::allocator >’ requested here
Information:(4630, 29) in instantiation of function template specialization ‘std::__1::shared_ptr::make_shared<>’ requested here
Error:(4274, 18) error: assigning to ‘std::__1::__shared_weak_count *’ from incompatible type ‘pointer’ (aka ‘std::__1::__shared_ptr_emplace<ofxAndroidVideoPlayer, std::__1::allocator > *’)
/Users/chenhongyu/code/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libcxx/include/iterator
Information:(1239, 53) ‘std::vector’ declared here
/Users/chenhongyu/code/openFrameworks-master/addons/ofxAndroid/src/ofxAndroidVideoGrabber.h
Error:(22, 2) error: no template named ‘vector’; did you mean ‘std::vector’?
Error:(93, 2) error: unknown type name ‘shared_ptr’
Error:(93, 12) error: expected member name or ‘;’ after declaration specifiers
/Users/chenhongyu/code/openFrameworks-master/addons/ofxAndroid/src/ofxAndroidSoundPlayer.h
Error:(11, 12) error: unknown type name ‘string’; did you mean ‘jstring’?
Warning:(11, 7) warning: ‘ofxAndroidSoundPlayer::load’ hides overloaded virtual function [-Woverloaded-virtual]
/Users/chenhongyu/code/openFrameworks-master/libs/openFrameworks/sound/ofBaseSoundPlayer.h
Information:(19, 18) hidden overloaded virtual function ‘ofBaseSoundPlayer::load’ declared here: type mismatch at 1st parameter (‘const std::filesystem::path &’ vs ‘jstring’ (aka ‘_jstring *’))
/Users/chenhongyu/code/openFrameworks-master/libs/openFrameworks/app/ofAppBaseWindow.h
Information:(45, 20) overridden virtual function is here
virtual glm::vec2 getWindowPosition() {return glm::vec2(); }
~~~~~~~~~ ^
In file included from /Users/chenhongyu/code/openFrameworks-master/libs/openFrameworks/app/ofMainLoop.cpp:19:
/Users/chenhongyu/code/openFrameworks-master/addons/ofxAndroid/src/ofAppAndroidWindow.h:40:10: error: virtual function ‘getWindowSize’ has a different return type (‘ofPoint’ (aka ‘ofVec3f’)) than the function it overrides (which has return type ‘glm::vec2’ (aka ‘tvec2<float, highp>’))
ofPoint getWindowSize();
~~~~~~~ ^
/Users/chenhongyu/code/openFrameworks-master/libs/openFrameworks/app/ofAppBaseWindow.h:46:20: note: overridden virtual function is here
virtual glm::vec2 getWindowSize(){return glm::vec2(); }
~~~~~~~~~ ^
In file included from /Users/chenhongyu/code/openFrameworks-master/libs/openFrameworks/app/ofMainLoop.cpp:19:
/Users/chenhongyu/code/openFrameworks-master/addons/ofxAndroid/src/ofAppAndroidWindow.h:41:10: error: virtual function ‘getScreenSize’ has a different return type (‘ofPoint’ (aka ‘ofVec3f’)) than the function it overrides (which has return type ‘glm::vec2’ (aka ‘tvec2<float, highp>’))
ofPoint getScreenSize(){return getWindowSize(); }
~~~~~~~ ^
/Users/chenhongyu/code/openFrameworks-master/libs/openFrameworks/app/ofAppBaseWindow.h:47:20: note: overridden virtual function is here
virtual glm::vec2 getScreenSize(){return glm::vec2(); }
~~~~~~~~~ ^
In file included from /Users/chenhongyu/code/openFrameworks-master/libs/openFrameworks/app/ofMainLoop.cpp:19:
/Users/chenhongyu/code/openFrameworks-master/addons/ofxAndroid/src/ofAppAndroidWindow.h:48:22: error: unknown type name ‘string’; did you mean ‘std::string’?
void setWindowTitle(string title){}
^~~~~~
std::string
/Users/chenhongyu/code/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libcxx/include/iosfwd:189:65: note: ‘std::string’ declared here
/Users/chenhongyu/code/openFrameworks-master/addons/ofxAndroid/src/ofAppAndroidWindow.h
Error:(39, 10) error: virtual function ‘getWindowPosition’ has a different return type (‘ofPoint’ (aka ‘ofVec3f’)) than the function it overrides (which has return type ‘glm::vec2’ (aka ‘tvec2<float, highp>’))
Error:(62, 2) error: unknown type name ‘shared_ptr’
Error:(62, 12) error: expected member name or ‘;’ after declaration specifiers
Error:(69, 2) error: unknown type name ‘shared_ptr’
Error:(69, 12) error: expected member name or ‘;’ after declaration specifiers
/Users/chenhongyu/code/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libcxx/include/iosfwd
Information:(189, 65) ‘std::string’ declared here
/Users/chenhongyu/code/openFrameworks-master/addons/ofxAndroid/src/ofxAndroidLogChannel.h
Error:(16, 35) error: unknown type name ‘string’; did you mean ‘std::string’?
Error:(16, 58) error: unknown type name ‘string’; did you mean ‘std::string’?
Error:(17, 38) error: unknown type name ‘string’; did you mean ‘std::string’?
Error:(18, 38) error: unknown type name ‘string’; did you mean ‘std::string’?
/Users/chenhongyu/code/openFrameworks-master/libs/openFrameworks/utils/ofUtils.cpp
Error:(1130, 3) error: no matching function for call to ‘ofxAndroidLaunchBrowser’
/Users/chenhongyu/code/openFrameworks-master/addons/ofxAndroid/src/ofxAndroidUtils.h
Error:(62, 25) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(63, 27) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(65, 28) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(66, 25) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(67, 29) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(67, 46) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(68, 1) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(69, 29) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(69, 49) error: no template named ‘vector’; did you mean ‘std::vector’?
Error:(69, 56) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(71, 22) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(80, 1) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(80, 31) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(82, 1) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(86, 30) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(95, 35) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(62, 25) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(63, 27) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(65, 28) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(66, 25) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(67, 29) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(67, 46) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(68, 1) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(69, 29) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(69, 49) error: no template named ‘vector’; did you mean ‘std::vector’?
Error:(69, 56) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(71, 22) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(62, 25) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(63, 27) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(65, 28) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(66, 25) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(67, 29) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(67, 46) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(68, 1) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(69, 29) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(69, 49) error: no template named ‘vector’; did you mean ‘std::vector’?
Error:(69, 56) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(71, 22) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(80, 1) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(80, 31) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(82, 1) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(86, 30) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(95, 35) error: unknown type name ‘string’; did you mean ‘jstring’?
Information:(86, 6) candidate function not viable: no known conversion from ‘std::string’ (aka ‘basic_string<char, char_traits, allocator >’) to ‘jstring’ (aka ‘_jstring *’) for 1st argument
Error:(62, 25) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(63, 27) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(65, 28) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(66, 25) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(67, 29) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(67, 46) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(68, 1) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(69, 29) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(69, 49) error: no template named ‘vector’; did you mean ‘std::vector’?
Error:(69, 56) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(71, 22) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(80, 1) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(80, 31) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(82, 1) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(86, 30) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(95, 35) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(62, 25) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(63, 27) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(65, 28) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(66, 25) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(67, 29) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(67, 46) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(68, 1) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(69, 29) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(69, 49) error: no template named ‘vector’; did you mean ‘std::vector’?
Error:(69, 56) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(71, 22) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(80, 1) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(80, 31) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(82, 1) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(86, 30) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(95, 35) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(62, 25) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(63, 27) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(65, 28) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(66, 25) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(67, 29) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(67, 46) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(68, 1) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(69, 29) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(69, 49) error: no template named ‘vector’; did you mean ‘std::vector’?
Error:(69, 56) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(71, 22) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(80, 1) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(80, 31) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(82, 1) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(86, 30) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:(95, 35) error: unknown type name ‘string’; did you mean ‘jstring’?
Error:Execution failed for task ‘:openFrameworksProject:compileOpenFrameworksLibArmeabi-v7aDebugArm7StaticLibraryOpenFrameworksLibMainCpp’.
Multiple build operations failed.
C++ compiler failed while compiling ofVideoPlayer.cpp.
C++ compiler failed while compiling ofVideoGrabber.cpp.
C++ compiler failed while compiling ofThread.cpp.
C++ compiler failed while compiling ofAppRunner.cpp.
C++ compiler failed while compiling ofMainLoop.cpp.
C++ compiler failed while compiling ofLog.cpp.
C++ compiler failed while compiling ofUtils.cpp.
C++ compiler failed while compiling ofFbo.cpp.
C++ compiler failed while compiling ofShader.cpp.
C++ compiler failed while compiling ofVboMesh.cpp.
…and 6 more failures.
See the complete log at: file:///Users/chenhongyu/code/openFrameworks-master/libs/openFrameworksCompiled/project/android/build/tmp/compileOpenFrameworksLibArmeabi-v7aDebugArm7StaticLibraryOpenFrameworksLibMainCpp/output.txt
Information:BUILD FAILED
Information:Total time: 5 mins 28.449 secs
Information:109 errors
Information:6 warnings
Information:See complete output in console