Well you could start with cleaning up the indentation, so that people would want to read it. That's probably why it was ignored first time around.
Code:
#include<iostream>
#include<string>
#include<fstream>
#include<iomanip>
#include<sstream>
#include<cassert> //!! added
using namespace std;
struct NVH {
char name[200];
int points[200];
};
int main()
{
ifstream file;
file.open("input.txt");
ifstream pch;
pch.open("input1.txt");
char input2[300], name2[300];
ofstream pchout;
pchout.open("output.txt");
struct NVH n[200];
long int i, j, k, l, m, p, a, b, c, x, y, z, r, s, d, f;
float e;
long int g, h, t;
int u = 900, v = 400, w = 700;
char nam[300], name[300], input[300], name1[300];
string line;
file >> nam;
file >> c;
file >> nam;
file >> nam;
for (i = 0; i < c; i++) {
file >> n[i].name;
string str("$POINT ID = ");
string replace;
replace = n[i].name;
for (p = 0; p < 2; p++) {
file >> n[i].points[p];
}
x = n[i].points[0];
y = n[i].points[1];
for (j = x; j < y; j++) {
std::stringstream tc;
tc << j;
string integer = tc.str();
string search;
search = str + integer;
while (!pch.eof()) {
getline(pch, line);
assert(search != replace);
string::size_type pos = 0;
while ((pos = line.find(search, pos)) != string::npos) {
line.replace(pos + search.size(), search.size(), replace);
pos++;
}
pchout << line << endl;
}
}
}
file.close();
pch.close();
pchout.close();
return 0;
}
Next, get rid of all those useless unused variables.
Code:
$ g++ -W -Wall -ansi -pedantic -O2 foo.cpp
foo.cpp: In function ‘int main()’:
foo.cpp:22: warning: unused variable ‘input2’
foo.cpp:22: warning: unused variable ‘name2’
foo.cpp:29: warning: unused variable ‘k’
foo.cpp:29: warning: unused variable ‘l’
foo.cpp:29: warning: unused variable ‘m’
foo.cpp:29: warning: unused variable ‘a’
foo.cpp:29: warning: unused variable ‘b’
foo.cpp:29: warning: unused variable ‘z’
foo.cpp:29: warning: unused variable ‘r’
foo.cpp:29: warning: unused variable ‘s’
foo.cpp:29: warning: unused variable ‘d’
foo.cpp:29: warning: unused variable ‘f’
foo.cpp:30: warning: unused variable ‘e’
foo.cpp:31: warning: unused variable ‘g’
foo.cpp:31: warning: unused variable ‘h’
foo.cpp:31: warning: unused variable ‘t’
foo.cpp:32: warning: unused variable ‘u’
foo.cpp:32: warning: unused variable ‘v’
foo.cpp:32: warning: unused variable ‘w’
foo.cpp:33: warning: unused variable ‘name’
foo.cpp:33: warning: unused variable ‘input’
foo.cpp:33: warning: unused variable ‘name1’
I see there is an eof() in there, which is almost certainly wrong.
Cprogramming.com FAQ > Why it's bad to use feof() to control a loop
Once you reach the end of the file, you need to do something like fin.clear() to reset the eof() state, and then fin.seekg() to go back to the start of the file, if you want to read it again.