|
|
![]() |
| 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; } |
![]() |
|
Tags: array, c language, char array, cpp |
Thread Tools | Search this Thread |
|
![]() | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
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 |
Problems with a 2D array | Preetish | Software Development | 3 | 15-10-2009 11:58 PM |
XML to ARRAY | Vandam | Software Development | 3 | 29-06-2009 06:14 PM |
JAVA array | Daren | Software Development | 2 | 06-03-2009 06:13 PM |