Created
August 6, 2014 17:39
-
-
Save P1xt/fa6d66a3941406107386 to your computer and use it in GitHub Desktop.
CS107 Unit 1 Assessment Problem 0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Problem 0 | |
* To run this program, you'll need to have a file named | |
* datafile.dat in the working directory. | |
*/ | |
#include <iostream> | |
#include <fstream> // For ifstream | |
#include <string> | |
using namespace std; | |
int main() { | |
/* Open the file - else error and return */ | |
ifstream input("datafile.dat"); | |
string line; | |
if(!input.is_open()) { | |
cerr << "Cannot open file!" << endl; | |
return 0; | |
} | |
/* read each line from file */ | |
while (getline(input, line)) { | |
/* for each character in the line, print if not numeric */ | |
for (string::const_iterator it = line.begin(); it != line.end(); ++it) { | |
if (!(*it >= '0' && *it <= '9')) { | |
cout << *it; | |
} | |
} | |
cout << endl; /* terminate each line with endl for a line break */ | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment