जो मैं करने की कोशिश कर रहा हूं वह है कि लाइन लाइन द्वारा लाइन इनपुट करें और आउटपुट फ़ाइल में टोकन और आउटपुट करें। मेरे पास क्या है करने में सक्षम है फ़ाइल में पहली पंक्ति इनपुट है लेकिन मेरी समस्या यह है कि मैं अगली पंक्ति को टोकननाइज़ करने के लिए इनपुट करने में असमर्थ हूं ताकि इसे आउटपुट फ़ाइल में दूसरी पंक्ति के रूप में सहेजा जा सके, यह वही है जो मैं अब तक कर सकता था फ़ाइल में पहली पंक्ति इनपुट करने के लिए।इनपुट फ़ाइल से लाइन द्वारा इनपुट लाइन और strtok() और आउटपुट फ़ाइल में उत्पादन आउटपुट फ़ाइल
#include <iostream>
#include<string> //string library
#include<fstream> //I/O stream input and output library
using namespace std;
const int MAX=300; //intialization a constant called MAX for line length
int main()
{
ifstream in; //delcraing instream
ofstream out; //declaring outstream
char oneline[MAX]; //declaring character called oneline with a length MAX
in.open("infile.txt"); //open instream
out.open("outfile.txt"); //opens outstream
while(in)
{
in.getline(oneline,MAX); //get first line in instream
char *ptr; //Declaring a character pointer
ptr = strtok(oneline," ,");
//pointer scans first token in line and removes any delimiters
while(ptr!=NULL)
{
out<<ptr<<" "; //outputs file into copy file
ptr=strtok(NULL," ,");
//pointer moves to second token after first scan is over
}
}
in.close(); //closes in file
out.close(); //closes out file
return 0;
}