Strings

I am trying to make a small program, and I would like to know is it possible to make string variables in c++?
@ElmuKelmuZ

Yes it is. You must include the string header, as in #include <string> , and make a variable by declaring it as one. string Any_name = "Hello"; If you need a lot of the same, such as names of furniture, for instance, you could declare string furniture[3] = {"Sofa","Table","Lamp"}; and access each by its number. furniture[0] is the Sofa, furniture[1], the Table and Lamp is furniture[2].

Hope this helps you..
closed account (3qX21hU5)
Also it is important to note unless you are using

using namespace std;
or
using std::string;

You will need to include std:: infront of your strings. Example

1
2
3
4
5
6
7
8
#include <string>

int main()
{

std::string myname; // std::string declares a varible of type string named myname

}


is the same as

1
2
3
4
5
6
7
8
9
10
11
#include <string>

using namespace std;

int main()
{

string myname;

}
Last edited on
http://www.cplusplus.com/reference/string/string/ for everything you want to know on std::string
Topic archived. No new replies allowed.