I am to request a file description and a string from a user then state the number of occurrences of the string in the file. Maybe I made mistakes in my notes. Also, getline(cin, InputLine, i\ni). The i\ni is not 'i's. What is the character and how do I type it?
Code:/* Write a program that requests a file description (word) and a string from the user then states the number of occurances of the string in the file. (We will search for the letter 'a'.) If the file does not exist, the program should state this to the user.*/ #include <iostream> #include <fstream> #include <conio.h> #include <string> using namespace std; int main() { //Step01: Declare Memory Locations ifstream InFile; string MyWord; //Location of text to be searched for //Step02: Initialize Memory Locations InFile.open("C:/Temp/TestData1.txt");/*Location of file to be read*/ int Index = 0; //Counter for occurances //Step03: Do the Work cout << "Please enter text: "; cin >> MyWord; if (!InFile.is_open()) { cerr << "File does not exist" << endl; getch(); exit(0); } while(InFile.open) { getline(cin, MyWord, i\ni); string Letter = MyWord.find("a"); Letter = MyWord.substr(0,1); Index++; } //Step04: Do the Work InFile.close; cout << endl; getch(); return 0; }



LinkBack URL
About LinkBacks


