|
| |||||||||
| Tags: array, c language, char array, cpp |
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| Assigning an array to an array
Could someone explain to me why we can not assign an array of type char to an array of char? An example to be clear: Code: #include <iostream>
using namespace std;
int main ()
{
char word[25];
char copyword[25];
cin >> word;
word = copyword;
cout << copyword;
} Quote:
Code: #include <iostream>
using namespace std;
int main ()
{
char matrix [20][20];
char word[25];
cin >> word;
for (int i = 0; word[i] != '\0'; i++)
{
matrix [i] = word;
}
} |
|
#2
| |||
| |||
| Re: Assigning an array to an array
For compatibility with C++ for which that can be compatible with earlier language that had a model of different picture. That's why things like boost::array is not bad because it gives a true semantics of first order in C++ array. It is safer to use boost::array then a plain array, because it is not a pointer in disguise. It is much faster than normal array. |
|
#3
| |||
| |||
| Re: Assigning an array to an array
Can you to explain me what is "boost:: array"? How is it used? What can do what? An example would be more than enough to understand the concept of boost:: array. Header <boost/array.hpp> consists of the below code: Code: namespace boost {
template<typename T, std::size_t N> class array;
template<typename T, std::size_t N> void swap(array<T, N>&, array<T, N>&);
template<typename T, std::size_t N>
bool operator==(const array<T, N>&, const array<T, N>&);
template<typename T, std::size_t N>
bool operator!=(const array<T, N>&, const array<T, N>&);
template<typename T, std::size_t N>
bool operator<(const array<T, N>&, const array<T, N>&);
template<typename T, std::size_t N>
bool operator>(const array<T, N>&, const array<T, N>&);
template<typename T, std::size_t N>
bool operator<=(const array<T, N>&, const array<T, N>&);
template<typename T, std::size_t N>
bool operator>=(const array<T, N>&, const array<T, N>&);
} |
|
#4
| |||
| |||
| Re: Assigning an array to an array
boost:: array template is a class that behaves exactly like an array in terms of behavior and performance but also gives him a real semantic value (copy, placement, etc.). Usage example: Code: #include <boost/array.hpp>
int main()
{
const int size = 5;
boost::array<double,size> arr;
for (int p=0; p!=size+1; ++p) arr.at(p)=p; //Checks range
for (int i=0; i!=size+1; ++i) arr[i]=i; //Does not check range
return 0;
} |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "Assigning an array to an array" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Array of char and int | Jensen Ackles | Software Development | 5 | 23-03-2010 10:50 AM |
| Array of array in PHP | cyber-noob | Software Development | 4 | 26-02-2010 05:13 PM |
| C# array help | Daren | Software Development | 5 | 03-01-2010 07:12 AM |
| XML to ARRAY | Vandam | Software Development | 3 | 29-06-2009 07:14 PM |
| Array Functions in PHP | SuperXCM | Software Development | 2 | 26-03-2009 11:57 AM |