• Register
1 vote


I wrote a simple program in c++ and it throws back an error: “string does not name a type

Find my program snippet below:

#include <iostream>
#include <fstream>
#include <string>

using namespace std;
class MyClass
      string description; 
      int test;              

Could you please pull me up?

12 7 7
15,250 points

1 Answer

0 votes


You can’t define a string like that. Change the "string" to "std::string

13 9 6
94,240 points

Related questions

1 vote
1 answer 12 views
Problem: Hello guys, I am a novice in the programming world. I&rsquo;ve started learning with the C/C++ language. I&rsquo;ve got a piece of C++ code with two classes. The program is throwing a compile-time error does not name a type I am ... receiveMessage(); vector<Message> *dataMessageList; }; I am looking forward to having a legitimate solution to the problem. Thanks for your kind concern
asked Apr 29 Gavin 15.3k points
0 votes
1 answer 16 views
I have created a Person class with two attributes, age and name, and later I have implemented a vector of people to try to print the attributes of the objects entered there. When I try to access the age attribute, there is no problem and it prints the values to me, but when trying to access ... people_vector.begin ();   while (it! = vector_people.end ())   {     it-> getName ();     it ++;   } }
asked Aug 15 game 4.6k points
0 votes
1 answer 4 views
Problem: Hi there! I have a class named vehicle and now I want to make objects of this class and instantiate them with some value. How can I instantiate an object of a custom class in C++?
asked Oct 13 Sheeza 2.9k points
1 vote
1 answer 270 views
Problem : Currently I have newly joined a DLL project I am trying to write the class which has variables and functions in its header and the required definitions in the .cpp file. In my constructor I really have no problems but in my getMyPoint() function I often face below ... symbol errors in a same place, in the getMyPoint(). I am looking for C++ expert who can help me in fixing above error.
asked Apr 27 stewart 4k points
0 votes
1 answer 19 views
My binary search function does not return a variable (C ++) int binarySearch (vector <Data> vectorBS, string x) { lower int = 0; int top = vectorBS.size () - 1; bool flag = false; while (lower <= upper) {     int half = (lower + upper) / 2;     if (vectorBS ... half; } else {     return -1; } } What could be the problem? half is declared inside the function and should return it when flag == true.
asked Aug 15 game 4.6k points