What Variable should I use to store text
What Variable should I use to store text
Look at C-style string (char*'s) or, the preferable std::string class in <string> (C++ Standard Library).
The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.
Since this is the C++ area, I would suggest a string. You can learn all about it here.
- Stack Overflow
Segmentation Fault: I am an error in which a running program attempts to access memory not allocated to it and core dumps with a segmentation violation error. This is often caused by improper usage of pointers, attempts to access a non-existent or read-only physical memory address, re-use of memory if freed within the same scope, de-referencing a null pointer, or (in C) inadvertently using a non-pointer variable as a pointer.
Don't worry, the link Stack Overflow provided is a good reference, but the string class is much easier to use than reading that page would suggest. I don't know of any specific tutorials on string that would be easier to follow, but I'm sure there are some.
Oh,
I must admit it is a good reference compared to learning about it. Here are some tutorials that you may find helpful:
- C++ String Class Tutorial
- C++ Input and Output
- Manipulating String Variables
- C++ Standard Template Library
- Stack Overflow
Segmentation Fault: I am an error in which a running program attempts to access memory not allocated to it and core dumps with a segmentation violation error. This is often caused by improper usage of pointers, attempts to access a non-existent or read-only physical memory address, re-use of memory if freed within the same scope, de-referencing a null pointer, or (in C) inadvertently using a non-pointer variable as a pointer.
Nice, thank you. Upon quick skimming I like the fourth one best.
Yeah but the third one didn't exactly give me the warm fuzzies:
That using namespace std; line doesn't have anything to do with the string.h header does it? Maybe string but not string.h. Also, I wouldn't say that simply including a header lets you "recognize" the string library.A string is a sequence of characters. In order to use strings in your programs, you need to first make sure that you are using a recognized string library. This can be achieved by adding the following to the top of your code (where you place your header files):
#include<string.h>
using namespace std;
The second line tells the compiler to use the standard "namespace" for the string library.
The rest is fairly simple. Here is how a sample program using strings would look like:
#include <iostream>
#include <string>
using namespace std;
void main() // Yuck
{
string firstname="test";
cout << "Enter first name: ";
cin >> firstname;
cout << firstname << endl;
}
"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens
Some tutorials don't give accurate information. It is hard to find tutorials on <string>, so I just posted all the information I had. Sadly, some people still use incorrect syntax and other idio's like void main() when they shouldn't. A post I made a while back shows why it isn't good to use these types of coding practices.
- Stack Overflow
Segmentation Fault: I am an error in which a running program attempts to access memory not allocated to it and core dumps with a segmentation violation error. This is often caused by improper usage of pointers, attempts to access a non-existent or read-only physical memory address, re-use of memory if freed within the same scope, de-referencing a null pointer, or (in C) inadvertently using a non-pointer variable as a pointer.