Содержание
- How set std::string type on lldb?
- 3 Answers 3
- error: ‘string’ in namespace ‘std’ does not name a type
- 1 Answer 1
- Related
- Hot Network Questions
- Subscribe to RSS
- «string is not a type» in namespace
- 3 Answers 3
- Related
- Hot Network Questions
- Subscribe to RSS
- Error no type named string in namespace std
- string in namespace std does not name a type
- All 3 Replies
How set std::string type on lldb?
I have the following code:
When i will debug with lldb i want set a std::string like i set this int :
expr std::string $name = «Foo»
error: no type named ‘string’ in namespace ‘std’
Does anyone understand what is going on? How can i create a std::string on lldb ?
Obs:
When i print name , lldb give me this type std::__1::string for std::string :
3 Answers 3
std::string looks simple from the outside but it’s actually a quite complex little beast.
For instance, all the std::string constructors except the copy constructors take defaulted arguments (allocators and the like) that most normal C++ users never override, and so don’t know about. Since we are getting our information about the type from the DWARF debug info, we are restricted by what it represents. It doesn’t represent the values of defaulted arguments, however, so we don’t know how to fill them in.
You can try a little harder by reading the string header, and you figure out you need to provide a size and an allocator, and get to something like:
That fails because the allocator is everywhere inlined, so lldb can’t find a constructor to call for it.
The real solution to this is to have lldb rebuild the std module from headers, import the resultant clang module into lldb’s compiler and use that to create these values. At that point we’d have the information needed to do this job. For instance we would know about defaulted arguments, and could instantiate the missing allocator from the module.
But building a Clang Module from the c++ std headers turns out not to be entirely trivial, so we’re still working on that.
Источник
error: ‘string’ in namespace ‘std’ does not name a type
I have this 2 separated class and i cant fix this compiler problem:
In file included from classA.cpp:2:0: classB.h:6:10: error: ‘string’ in namespace ‘std’ does not name a type std::string str; ^
In file included from classA.cpp:3:0: classA.h:6:25: warning: non-static data member initializers only available with -std=c++11 or -std=gnu++11 classB *ptr_b = new classB;
There is the classA.h:
I apreciate all the help you can give. I don´t know how to fix this and I’m going crazy.
Thanks for reading.
1 Answer 1
You need #include in classB.h . Right now classA.cpp includes classB.h with no prior #include anywhere, so the included reference to std::string in classB.h causes an error.
In general, if a name is used in a header foo.h , you should include the header bar.h that declares the name in foo.h , or forward-declare the name in foo.h . Otherwise everyone else who includes foo.h will need to remember to make sure bar.h gets included first.
Hot Network Questions
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.1.14.43159
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.
Источник
«string is not a type» in namespace
I write a program in c++ with two files.
When I compilered it, It’get wrong.
the wrong infomation is:
In file included from main.cpp:1:0:
var.hpp:9:5: Error: ‘string’ is not a type name
I don’t know why,I had include head file, but it still dosen’t work.
I write this code just for practice, not for work.
3 Answers 3
The problem is the namespace of string in var.hpp . string is the std namespace, but you are not telling the compiler that. You could fix it by putting using namespace std; in var.hpp , but the following is a better solution as it doesn’t clutter the global namespace with other things from std :
You have using namespace std; in your .cpp file, but it comes after the include of var.h . If you’re going to write the header like that, you should put using namespace std; in the header as well.
Alternativly you could use
This avoids having to type std::string in front of every string, and you don’t grab everything from the global namespace.
Hot Network Questions
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.
Site design / logo © 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA . rev 2023.1.14.43159
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.
Источник
Error no type named string in namespace std
HELP! i’m getting what seems like an erroneous error! i’ve got #include in the top of my .cpp, but i keep getting the error ‘string’ does not name a type when i try to compile! why. any ideas? i thought #include was what INCLUDED the library for using strings?? this is in a header file attached to a .cpp that i’m using to store classes and class member functions to be used by the client program, does that make a difference? i’ll throw up the part of my code where it says i have this problem.
please excuse the LIST of includes. my prof told me that if you don’t use it the compiler ignores it so it’s not a bad idea to just make a master list, so you don’t have to keep remembering to type in the ones you need.
Change «string» to «std::string»
Most likely you did not mean to comment out line 12.
Also, what your professor told you only applies when you have optimizations on — in debug mode (no optimizations) it does not apply.
Namespaces were meant to prevent cases where you give something the same name as something in one of those headers. When you write using namespace std you plop all of the stuff in the std namespace into the global namespace so you don’t have to type std:: before everything. It comes at a price: you may accidentally give something the same name as something in the std namespace and cover it up or make it ambiguous as to which you want.
Your fellow students who put std:: before everything have the right idea.
If it is really a hassle you can do things like this:
Источник
string in namespace std does not name a type
Hi guys. I’m aware of the requirement to specify std:: as the namespace for string in some way ( whether it be using namespace std etc) — but the following error has stumped me as to its cause.
This is the only error — and here is a (truncated) Conf.cpp.
Line 33 as shown in the code sample is the definition of the function returning a string.
I’ve tried combinations of using std::string, but each time it states something similar «string does not name a type», «std::string has not been declared» etc..
Any suggestions would be most helpful.
- 3 Contributors 3 Replies 5K Views 21 Hours Discussion Span Latest Post 13 Years Ago Latest Post by StuXYZ
> #include
This is the old C-style header
#ifndef Conf_H
#include «Conf.h»
#endif
Normally, the header include guards go inside the header file itself.
> #include
This is the old C-style header
#ifndef Conf_H
#include «Conf.h»
#endif
Normally, the header include guards go inside the header file itself.
so I should go back and make all me #include ‘s into #include ?
Using gcc, #include , provides a back-compatability system for stuff like using std::memcpy; etc.
You include that when you are using code that does not use the std::strcpy form but you want to just write strcpy(. ) . Since you almost never want using namespace std; it is a nice half-way house, for importing c like code.
So if you have not included #include , you have only a forward declaration for std::string. Hence the error. [Note that gcc use to include in a lot of other includes, but they have been moving towards a independent #include system, so as you go up the version number you need to be more exact on you #include’s. This means that although your code gets slightly longer your compile time goes down.
So in answer to the question you pose, yes you do need to add #include BUT you may ALSO need #include
We’re a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.
Reach out to all the awesome people in our software development community by starting your own topic. We equally welcome both specific questions as well as open-ended discussions.
Источник
- Forum
- General C++ Programming
- ‘string’ does not name a type
‘string’ does not name a type
HELP! i’m getting what seems like an erroneous error! i’ve got #include <string> in the top of my .cpp, but i keep getting the error ‘string’ does not name a type when i try to compile! why?!? any ideas? i thought #include <string> was what INCLUDED the library for using strings?? this is in a header file attached to a .cpp that i’m using to store classes and class member functions to be used by the client program, does that make a difference? i’ll throw up the part of my code where it says i have this problem..:
|
|
and the error says:
'string' does not name a type
please excuse the LIST of includes… my prof told me that if you don’t use it the compiler ignores it so it’s not a bad idea to just make a master list, so you don’t have to keep remembering to type in the ones you need…
Last edited on
Change «string» to «std::string»
Most likely you did not mean to comment out line 12.
Also, what your professor told you only applies when you have optimizations on — in debug mode (no optimizations) it does not apply.
Last edited on
oh! you’re right on line 12.. and if i uncomment it, i shouldn’t have any problems there right? also, i noticed in other student’s examples that they didn’t need to use the «namespace std;»
line in a header file, only in the main.cpp… but i didn’t notice SPECIFICALLY if they were using the std:: class scope every time… does having the namespace line in everything complicate things at all? or is it more about efficiency in coding when it comes to wether or not you inlcude it?
Namespaces were meant to prevent cases where you give something the same name as something in one of those headers. When you write using namespace std you plop all of the stuff in the std namespace into the global namespace so you don’t have to type std:: before everything. It comes at a price: you may accidentally give something the same name as something in the std namespace and cover it up or make it ambiguous as to which you want.
Your fellow students who put std:: before everything have the right idea.
If it is really a hassle you can do things like this:
|
|
Last edited on
ok so when using it i need to avoid using anything in the standard namespace, like pre-defined common functions etc. (toupper, aoti, etc. ) and i’m predefined classes like the c++ string class.. am i right?
Well, no — you should just get out of the habit of writing «using namespace std;» because then you never have to worry.
lol ok good point
just curious, is there a list on this site of the types that are found in std:: ? that way i can have a reference ?
wow right on the front page… sadly that explains why i didn’t see it… i’ve been using the search function for individuals references and never saw this page… well now i feel extra stupid but i also learned something, so i take solace in the fact that i may be stupid, but i’m getting smarter by the day
THANKS A LOT!!!!!!!!
Topic archived. No new replies allowed.
wolfdaver_77 6 / 6 / 5 Регистрация: 20.09.2016 Сообщений: 59 |
||||
1 |
||||
10.11.2016, 00:19. Показов 19955. Ответов 12 Метки нет (Все метки)
Только начал изучать Qt. Есть задача, которую надо сделать без средств Qt, а просто на c++ и консоли.
вот объявление класса, но везде, где используется string выдает ошибку: ‘string’ does not name a type. Как её исправить, объясните пожалуйста.
__________________
0 |
Programming Эксперт 94731 / 64177 / 26122 Регистрация: 12.04.2006 Сообщений: 116,782 |
10.11.2016, 00:19 |
12 |
Заблокирован |
|
10.11.2016, 00:47 |
2 |
. Как её исправить, объясните пожалуйста. В коде Qt можно писать всё, что и без него. #include <string> Должно работать, может у тебя там что — то с двойными включениями или что — то в этом духе… В общем по этому отрывку ничего не скажешь, прикрепляй архив с проектом
0 |
6 / 6 / 5 Регистрация: 20.09.2016 Сообщений: 59 |
|
10.11.2016, 01:03 [ТС] |
3 |
WarpDrive, Вот архив и скрин с ошибками, может архив не понадобится. Я уже везде стринг по отключал, ошибки те же, хз что это. Миниатюры
0 |
0x90h 659 / 439 / 155 Регистрация: 01.10.2015 Сообщений: 1,241 |
||||
10.11.2016, 01:18 |
4 |
|||
wolfdaver_77, ваш класс Employee является наследником класса Printable, который содержит чисто виртуальную функцию Добавлено через 3 минуты Код C:ProjectsCPPQT-2016-2-PrintEmployesmain.cpp:76: ошибка: 'endl' was not declared in this scope std::cout<<Taras.GetName()<<endl;
в employee.h И в целом ваша тема не имеет ни малейшего отношения к Qt, а ваше приложение — plain c++ application
0 |
6 / 6 / 5 Регистрация: 20.09.2016 Сообщений: 59 |
|
10.11.2016, 02:07 [ТС] |
5 |
0x90h, я создал вопрос в этой теме только потому, что в Qt Creator ошибка, думал, что тут ей и место) Добавлено через 7 минут
0 |
Заблокирован |
|
10.11.2016, 10:46 |
6 |
исправил то, на что Вы указали, но ошибок меньше не стало. Ох уж и стиль… Меня чуть не вывернуло, когда я проект открыл, без обид В общем, прикрепляю архив твоего «кхе кхе» софта, который у меня собирается без ошибок, если у тебя не так — ставь Qt.
0 |
Заблокирован |
|
10.11.2016, 12:28 |
7 |
а по поводу QtCreator — не более чем IDE Я бы сказал конкретнее, это просто IDE без всего, то есть голый редактор. У него нет ни встроенного компилятора, ни отладчика, ни сорцов стандартных типа iostrem или string там нет, вообще ничего там нет, в отличии от Visualtudio, в комплекте с которой поставляется всё. И это ТС должен чётко понимать, когда ставит QtCreator без комплекта Qt.
0 |
1936 / 1048 / 109 Регистрация: 29.03.2010 Сообщений: 3,167 |
|
10.11.2016, 12:34 |
8 |
И это ТС должен чётко понимать, когда ставит QtCreator без комплекта Qt. думаю вряд-ли ТС ставил голый креатор, без Qt-a, если учесть:
Только начал изучать Qt
0 |
6 / 6 / 5 Регистрация: 20.09.2016 Сообщений: 59 |
|
10.11.2016, 14:53 [ТС] |
9 |
WarpDrive, ставил весь qt. Преподы везде странные есть) я сам не понимаю в чем фишка, курсы называются c++/qt, а дз только по с++ было. Хотя, может я что то не понял, пришел уже после половины занятий. Добавлено через 7 минут
0 |
Заблокирован |
|
10.11.2016, 15:05 |
10 |
И хотел бы замечания по стилю услышать, если можно, хотелось бы знать что не так, что исправить надо. Ну… Там всё не так, для начала пиши хотя бы код с табуляцией, делай пустые стоки между значимыми элементами ..ой да много чего, просто соблюдай нормальный сталь форматирования. Создай какой — нибуть класс с помощью визарда QtCreator-а и посмотри, как он оформлен
WarpDrive, при запуске вашего проекта, те же ошибки( Какие ошибки — то? Не понимает, что такое std::string ? Если да — то ставь нормальный Qt. Ты его небойсь через онлайн инсталлятор ставил?
0 |
Форумчанин 8193 / 5043 / 1437 Регистрация: 29.11.2010 Сообщений: 13,453 |
|
10.11.2016, 15:13 |
11 |
хотел бы замечания по стилю услышать, если можно, хотелось бы знать что не так, что исправить надо. Замечания по поводу чуть меньше десятка строк из шапки темы?
0 |
6 / 6 / 5 Регистрация: 20.09.2016 Сообщений: 59 |
|
10.11.2016, 15:13 [ТС] |
12 |
WarpDrive, да, не понимает и нет, не через онлайн инсталятор. Сейчас попробую новый проект сделать, если будут те же ошибки, установлю заново.
0 |
6 / 6 / 5 Регистрация: 20.09.2016 Сообщений: 59 |
|
10.11.2016, 15:19 [ТС] |
13 |
MrGluck, дефайн это не моё, я скачал такой уже проект, нужно дописать решение.
0 |