Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

read from text file and rid white space

Posted on 2010-11-17
1
Medium Priority
?
453 Views
Last Modified: 2012-05-10
#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
0
Comment
Question by:jaypappas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 11

Accepted Solution

by:
cup earned 2000 total points
ID: 34161933
Which area are you having problems with?


You could use getch() or getchar() instead of system("PAUSE")
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question