Hi, as per the requirement i was asked to create a code that fetches each line under a particular section of a text file and store it in a variable.
#include <iostream>
#include <fstream>
#include <string.h>
using namespace std;
int main()
{
ifstream ifs("catter.txt");
string line;
char name[100];
char cat[100]="mkdir";
// read a line using getline upto a certain dliminater//
if(getline(ifs,line,'*'))
{
strcpy(name, line.c_str());
cout << name << endl;
system(name);
}
getchar();
}
and my text file content would be like this
mkdir c:\folder\new\
mkdir c:folder\old\*
out of this content the code printing the contents till the deliminater '*' but when i tried to call those lines individually to create new directory,it is calling only the first line "mkdir c:\folder\new\" and creating "new" folder in the desired location leaving the rest.so i want to read and store each line of the file using getline() fucntion.