Solved

read from text file and rid white space

Posted on 2010-11-17
1
444 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
1 Comment
 
LVL 11

Accepted Solution

by:
cup earned 500 total points
Comment Utility
Which area are you having problems with?


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

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
This article will show, step by step, how to integrate R code into a R Sweave document
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

743 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now