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
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?
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.
|
operkor 0 / 0 / 0 Регистрация: 27.11.2021 Сообщений: 76 |
||||
|
1 |
||||
|
09.04.2022, 23:27. Показов 1454. Ответов 7 Метки c++ 1курс, c++ builder (Все метки)
Все библиотеки вроде подключены, я не понимаю, почему при компиляции получаю такие ошибки:
__________________
0 |
|
Алексей1153 фрилансер 4430 / 3941 / 858 Регистрация: 11.10.2019 Сообщений: 10,417 |
||||
|
09.04.2022, 23:48 |
2 |
|||
|
operkor,
Добавлено через 1 минуту
1 |
|
0 / 0 / 0 Регистрация: 27.11.2021 Сообщений: 76 |
|
|
10.04.2022, 00:00 [ТС] |
3 |
|
Алексей1153, Упс, не заметил это, ошибки ушли, но проблема с мемо всё ещё осталась.
0 |
|
Модератор 8221 / 5459 / 2244 Регистрация: 21.01.2014 Сообщений: 23,492 Записей в блоге: 3 |
|
|
10.04.2022, 05:01 |
4 |
|
Я бы не использовал с C++ Builder типы данных из C++, в частности — std::string. Задачу можете озвучить?
0 |
|
0 / 0 / 0 Регистрация: 27.11.2021 Сообщений: 76 |
|
|
10.04.2022, 09:59 [ТС] |
5 |
|
D1973, Игра быки и коровы. Компьютер загадывает 4 значное число, я же, в свою очередь, отгадываю. Если цифра есть в загаданное числе, но не на своём месте, то я получаю «корову», если же цифра есть и на своём месте, то «быка».
0 |
|
Модератор 8221 / 5459 / 2244 Регистрация: 21.01.2014 Сообщений: 23,492 Записей в блоге: 3 |
|
|
10.04.2022, 14:56 |
6 |
|
operkor, а версия билдера какая?
0 |
|
Модератор 8221 / 5459 / 2244 Регистрация: 21.01.2014 Сообщений: 23,492 Записей в блоге: 3 |
|
|
10.04.2022, 16:35 |
7 |
|
РешениеНу раз ответа нет — вот вариант для RAD Studio 10.4, на другие версии при необходимости сами переделывайте, ничего специфического там нет, все стандартно. Миниатюры
2 |
|
0 / 0 / 0 Регистрация: 27.11.2021 Сообщений: 76 |
|
|
10.04.2022, 18:00 [ТС] |
8 |
|
D1973, Спасибо большое! Я как раз работаю в Rad Studio 10.4.
0 |
|
IT_Exp Эксперт 87844 / 49110 / 22898 Регистрация: 17.06.2006 Сообщений: 92,604 |
10.04.2022, 18:00 |
|
Помогаю со студенческими работами здесь
Ошибка в типе данных ‘String’ and ‘System::String’ ComboBox. Как разделить строку, чтобы часть слов вводилась в Memo, а остальное переменную String ?
Искать еще темы с ответами Или воспользуйтесь поиском по форуму: 8 |
![]:->](https://cyberstatic.net/images/smilies/aq.gif)
Сообщение было отмечено operkor как решение