I have a file which call text.cpp. My mission was read from the file.
text.cpp file (inside the file)
#include <iostream>
#include <cstring>
#include <ctype.h>
#include "program.h"
#include "binarytree.h"
#include "linkedlist.h"
When i detect
'#' symbol
the system will start looping, if it detect '<' & '"'
symbol, it will print out the remain word.
Example output : iostraem
I can detect '<'
symbol and print the output success.
But when i detect '"'
symbol, i can print remain word (program.h
), but it will follow 烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫
behind the word.
May i know whats wrong of my code?
My code was below:
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{ char temPlate[100];
char FileName[20];
cout << "Enter Filename:" ;
cin >> FileName;
fstream read(FileName);
if (read.is_open())
{
while(!read.eof())
{
read.getline(temPlate, 100);
for (int k = 0; k < 100 ;k++)
{
if(temPlate[k] == '#')
{
for(int i = 0; i < 100; i++)
{
if(temPlate[i] == '<' || temPlate[i] == '"')
{
for (int j = i+1; j < 100; j++)
{
if(temPlate[j] == '>' || temPlate[j] == '"')
{
break;
}
cout << temPlate[j];
}
cout <<endl;
}
}
}
}
}
}
else
{
cout << "File does not exist, press enter to exit the program." << endl;
system("pause");
exit(EXIT_SUCCESS);
}
system("pause");
}
Output:
Enter FileName: text.cpp
iostream
cstring
ctype.h
program.h
ype.h
binarytree.h
烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫
linkedlist.h
烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫烫