Re: C++ program paste paragraph of text
- From: ian middleton <ianmiddleton@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 23 Sep 2008 09:23:01 -0700
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
string line, paragraph, text, textin;
int i, location;
char* word = "virus"; // <--for example
// USER TO PASTE IN EMAIL
cout << "Paste text here:" << endl;
cin >> text;
cout << "You entered: " << text << endl;
getline(cin, text);
cin.ignore('\n');
ofstream filewriter;
filewriter.open("emailscan.txt"); // read in text to file called
filewriter << text << endl; // emailscan
if(!filewriter) // check that emailscan can be opened {
cout << "Error opening file for output" << endl;
return -1;
}
filewriter.close();
cout << "The text has been saved in emailscan.txt" << endl; // checkpoint
///////////////////////////////////////////////////////////////////////////////////////
// OPEN AND READ EMAILSCAN.TXT
ifstream filereader("emailscan.txt"); // first, read the text file
if( !filereader) // check that emailscan can be opened {
cout << "Error opening file for output" << endl;
return -1;
}
for(i = 0; ! filereader.eof(); i++){ // run a loop to read lines
getline(filereader,line); cout << line << endl;
///////////////////////////////////////////////////////////////////////////////////////
// FIND A WORD FOR EXAMPLE 'VIRUS'
if ((location = line.find(word, 0)) != string::npos) {
cout << "found \"" << word << "\" at location " << location << endl;
} else filereader.close(); // look for the word and if found state where
}
cout << line << endl;
filereader.close();
cout << "Iterations:" << i << endl; // how many lines?
return 0;
}
"Tim Roberts" wrote:
ian middleton <ianmiddleton@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:.
Hello, I'm writing a C++ program that scans emails for words on our school
"banned word list".
I have got to the point where we can paste text from an email into command
line which gets saved in a .txt file called 'emailscan' - this is then read
by ifstream and scanned for the chosen word which if found is returned with
its location
The problem is that we cannot paste more than a single paragraph of text.
For example if we copy an entire email, which more often than not contains
several carriage returns, only the first block of text before the first
carriage return is fed into the emailscan.txt file and subsequently only this
part of the email is scanned.
Is there a way of ignoring/discarding carriage returns or converting text
after the cin >> operator in order to merge all the text into one 'paragraph'?
Why don't you post your code? The answer depends on how you are doing the
reading.
--
Tim Roberts, timr@xxxxxxxxx
Providenza & Boekelheide, Inc.
- Follow-Ups:
- Re: C++ program paste paragraph of text
- From: Tim Roberts
- Re: C++ program paste paragraph of text
- From: Giovanni Dicanio
- Re: C++ program paste paragraph of text
- References:
- C++ program paste paragraph of text
- From: ian middleton
- Re: C++ program paste paragraph of text
- From: Tim Roberts
- C++ program paste paragraph of text
- Prev by Date: Re: How to detect hot locks !
- Next by Date: Re: C++ program paste paragraph of text
- Previous by thread: Re: C++ program paste paragraph of text
- Next by thread: Re: C++ program paste paragraph of text
- Index(es):
Relevant Pages
|