Link to home
Start Free TrialLog in
Avatar of jaypappas
jaypappas

asked on

read from text file and rid white space

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
using std::cin;
using std::cout;
using std::string;
string display(string);
const int size=32;
char cword[size];
string word;
int arr[size]={0};
int x = 0, len=0;

int main ()
{
    string array[5]; // creates array to hold names
     
    short loop=0; //short for loop for input
	display(cword);
    string line; //this will contain the data read from the file
    ifstream myfile ("testfile1.txt"); //opening the file.
    if (myfile.is_open()) //if the file is open
    {
        while (! myfile.eof() ) //while the end of file is NOT reached
        {
         
           getline (myfile,line); //get one line from the file
          
           display(line);
          
            loop++;
             
        }
        myfile.close(); //closing the file
    }
    else cout << "Unable to open file"; //if the file is not open output

    system("PAUSE");
    return 0;
}
string display(string word) {
  
   len=word.length();
  
   for (x=0;x < len;x++) {    // While the string isn't at the end...
        
        if (int(word[x]!=40)){
       cout << word[x] ;//<< " : "<< int(word[x]);    // Display char and ascii
        
        arr[x]=int(word[x]);
                            }
           
    }
    
return word;
}

Open in new window

testfile1.txt
ASKER CERTIFIED SOLUTION
Avatar of cup
cup

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial