#include<stdio.h>
#include<conio.h>
#include<iostream>
#include <fstream>
#include<string>
using namespace std;
int main()
{
// & Attempting to open an text file.
string a[255];
char buffer[225];
char *print_buffer;
char inputFile[]="c://dev-cpp//untitled2.cpp";
ifstream input(inputFile);
ofstream output;
output.open("example.txt");
if (!input)
cout << "Error in file name";
else
{
cout << "File: " << inputFile << endl;
while (!input.eof())
{
input.getline(buffer,255);
print_buffer = strstr(buffer,"//"); // This gives you the pointer pointing to the location where your // is in the line
// else it will return NULL.
if(print_buffer!=NULL&&((*print_buffer)==buffer[0]||((*(print_buffer-1))==' ' || (*(print_buffer-1))=='\t')))
{
cout << (print_buffer+2) << endl;
out_stream.write((print_buffer+2),strlen((print_buffer+2)));
out_stream.put('\n');
}
}
}
getch();
return 0;
}
This is what I tried and it worked absolutely fine for me. In my previous post, I have attached the output I got too!
Please check if you are doing anything different. or whether it is due to the IDE.

New Topic/Question
Reply




MultiQuote








|