Skip to content

Instantly share code, notes, and snippets.

@P1xt
Created August 6, 2014 17:39
Show Gist options
  • Save P1xt/fa6d66a3941406107386 to your computer and use it in GitHub Desktop.
Save P1xt/fa6d66a3941406107386 to your computer and use it in GitHub Desktop.
CS107 Unit 1 Assessment Problem 0
/* 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