yeah, so I never can understand char, like, i have looked at this site's reference page and tutorials and stuff, and i still dont really get it. Is it something that is that important to learn for a programmer? Any help would be nice...
Char is basically just a character. Surely you aren't getting confused about that? Anyway, apart from that, you may be getting confused about C-Strings or char arrays, and how to do copy / length / comparison with them. As something that is important to learn for a programmer, it depends. Nowadays, C-Style strings should be avoided where possible, in favour of the C++ 'string' class, which automatically provides all the functionality required for a copy / length / comparison / whatever. However, they can be useful when interacting with C API's, though even then std::string can be used (with its c_str() member).
I am not necessarily confused about it being a character, just how to use them. I just use the <string> library and the std namespace, so really is char basically for text like strings, or what?
Hi, I'm new to this too, and at first I couldn't stop my char variable from out-putting wingdings.
But here's an example of using char.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <iostream>
usingnamespace std;
int main()
{
//Declare string size 100.
char string[100];
//Prompt user to input a word.
cout << "Please enter a word." << endl;
//Reads input, store in string, \n waits for user to push enter.
cin.getline(string, 100, '\n');
//Outputs first character in string.
cout << "Your word started with a: " << string[0] << endl;
cin.get();
}
I'm now working on a simple dungeon crawl. I use an array to assign values to the board. I have two options.
int array[8][10] and I set them all to 0. The board looked like this:
00000000000
00000000000
00000000000
00000000000
00000000000
00000000000
00000000000
00000000000