Thread: Arrays, pointers and strings

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    29

    Arrays, pointers and strings

    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;
    }
    Last edited by Apropos; 03-21-2005 at 06:50 PM.
    Not to know, not to learn is shame

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Concatenating strings (dynamic array using pointers)
    By Tankndozer in forum C Programming
    Replies: 8
    Last Post: 07-01-2004, 07:27 AM
  2. working with strings arrays and pointers
    By Nutka in forum C Programming
    Replies: 4
    Last Post: 10-30-2002, 08:32 PM
  3. hangman need help with strings and pointers
    By Unregistered in forum C Programming
    Replies: 2
    Last Post: 03-27-2002, 09:13 AM
  4. Pointers to pointers to strings
    By Natase in forum C Programming
    Replies: 2
    Last Post: 09-17-2001, 11:30 PM
  5. pointer to pointers to arrays of strings??
    By Binkstone in forum C Programming
    Replies: 8
    Last Post: 09-14-2001, 02:56 AM