View Single Post
Old Jul 19th, 2005, 12:30 PM   #4
skuinders
Hobbyist Programmer
 
skuinders's Avatar
 
Join Date: Jun 2005
Location: MA, US
Posts: 204
Rep Power: 4 skuinders is on a distinguished road
1. My fix works fine for me. Here is all of the code:
#include <iostream>
#define dc42 "Forty-Two"
int my_age = 20;
int main () 
{
	const char lang[4] = "C++";
	char me[6] = "Broax";
	std::cout << me << " is learning " << lang << " at the age of " << my_age << "...\bWhy?...\b\t" << dc42;
	return 0;
}
2. Typically, you don't use char[] arrays for strings in C++. In C, there is no string data type, only char[] arrays, so you have to use them. But C++ has the string data type, so you would normally use that. Here is the program using string:
#include <iostream>
#define dc42 "Forty-Two"
int my_age = 20;
int main () 
{
	std::string lang = "C++";
	std::string me = "Broax";
	std::cout << me << " is learning " << lang << " at the age of " << my_age << "...\bWhy?...\b\t" << dc42;
	return 0;
}
Since you didn't seem to be working with strings, I suggested using a char[] array. The char data type is used for representing a single character such as 'a' or '%'. You were assigning a string of characters to a memory location which was expecting a single character. So, by changing it to a char[] array, you can store the string (or array) of characters successfully.
__________________
"A stupid man's report of what a clever man says can never be accurate, because he unconciously translates what he hears into something he can understand."
- B. Russell

http://web.bryant.edu/~srk2
skuinders is offline   Reply With Quote