Hi@all
I am writing a program about pointers and strings but I am stuck on part of it.
I am trying to read three words from a file. There is only one word in each line therefore I have three lines.
In this part, the program asks me store words in an array of pointers. The pointers are to be pointers to string objects.
Now, I am just trying trying to read words and print them. I think there is a logical problem because compiler says everything is ok.
Can you guys help me to figure out my problem?
thanks
My code;
Code:#include <iostream> #include <string> #include <fstream> using namespace std; int main() { string *pointer[3]; string number; ifstream infile; infile.open("words.txt"); for (int i=0; i<3; i++) { infile >> number; *pointer[i]=number; } for (int m=0; m<3; m++) cout <<*pointer[m]<<' '; cout <<endl; return 0; }