Re: C++ program paste paragraph of text

Tech-Archive recommends: Fix windows errors by optimizing your registry



#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.

.



Relevant Pages

  • Re: macro to take out spaces
    ... Occasionally there appear strange characters (especially in text pasted from ... the Web) that are displayed as paragraph breaks but are actually line ... > carriage, text, etc. Cannot figure it out for the life ...
    (microsoft.public.word.docmanagement)
  • Re: Typing on an existing document
    ... Yep, good suggestion, you can indeed use paragraph marks or carriage ... It's important to distinguish between carriage returns and paragraph ... hold both up to a strong light to check your alignment. ...
    (microsoft.public.mac.office.word)
  • RE: Different types of paragraph marks...
    ... seen the different paragraph marks, instead of the pilcrow, was on a laptop ... I know the difference between a "hard carriage return" and a "soft carriage ... the bent arrow symbolizing the soft carriage return has a longer ...
    (microsoft.public.word.docmanagement)
  • Re: Carriage returns between tables
    ... Word refuses to let F&R do anything with a paragraph ... Word MVP FAQ site: http://word.mvps.org ... I now have a situation in which a single carriage return ... > Normal style, of the carriage returns between tables, to a dedicated ...
    (microsoft.public.word.docmanagement)
  • Re: Miraculous survival of remote control
    ... A paragraph that was 9 lines long as I wrote it. ... Likewise it's agism and not ageism. ... I can't claim the credit for that - but I did influence the OP ... into usage of the carriage return. ...
    (uk.media.tv.misc)