Hi Jerry, thanks for the info. The books are ordered and should be here soon. In addition to your recommendation I also bought Practical C++ programming. I am a great fan of O'Reilly products. Another quick question for anyone before the books arrive, how would you get the array to take strings. I obviously changed from int to char, but instead of holding full words, it holds the characters of each word. Thanks ------------------------------------------------------- On Fri, 2 May 2003 11:50:21 +0000 Gedi <gedi@ntlworld.com> wrote:
I've just started to learn C++ in the last few days and have some accross a small problem. Here is a few corrections to your code: #include <iostream> #include <iomanip> using std::cout; using std::cin; using std::endl; int ix, array[10];
int main() { for(ix = 0; ix < 10; ix++) { cout << "Enter string: "; cin >> array[ix]; } // cout << array; // a little unsure as to how you print the strings out as a whole and seperatly cout << array[1] << endl; cout << array[3] << endl; return 0; } My changes are: 1. remove the .h for the header files. The older headers are deprecated. 2. cin and cout are in namespace std. You could have used "using namespace std;" as an alternative. 3. index is a Linux function and declared in string.h which is implicitly included. 4. Make sure you have line endings. It is best to use endl from the iomanip header rather than '\n', but '\n' or "\n" woould have worked fine also. 5. You cannot print an entire array unless the class includes the appropriate friend functions overloading the << operator. Since int is a basic type, there is no support for it in the language. In your case, cout << array << endl; will print out the address of the array. 6. Your "Enter string" comment is a bit of a misnomer. You should ask for a number since you are entering and int. 7. main should return something. I suggest you get a good book on C++. Bruce Eckel's Thinking in C++ is available online: http://www.mindview.net/Books/TICPP/ThinkingInCPP2e.html Additionally another book I use is "The C++ Primer". Several books on C++ have been discussed on this forum, and you can check the archives. -- Jerry Feldman <gaf@blu.org> Boston Linux and Unix user group http://www.blu.org PGP key id:C5061EA9 PGP Key fingerprint:053C 73EC 3AC1 5C44 3E14 9245 FB00 3ED5 C506 1EA9