I am writting a code that opens a file and take input a line at a time. It would store that line of info in a string and then I want to split that string up into little strings and store those strings in a vector. This is what I have so far but im getting an error can anyone help me with this.
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
//class Log_Entry
//{
// public:
// Log_Entry(strin g);
// string get_host() const { return _host; }
// private:
// string _host;
//};
int main ()
{
string line;
ifstream myfile ("example.txt") ;
if (myfile.is_open ())
{
while (! myfile.eof() )
{
getline (myfile,line);
int i = 0;
string s;
int index = 0;
while(line[i] != '')
{
s[index] = line[i];
i++;
index++;
}
cout << s << endl;
}
myfile.close();
}
else cout << "Unable to open file";
return 0;
}
im then going to return the vector entries into a class.
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
//class Log_Entry
//{
// public:
// Log_Entry(strin g);
// string get_host() const { return _host; }
// private:
// string _host;
//};
int main ()
{
string line;
ifstream myfile ("example.txt") ;
if (myfile.is_open ())
{
while (! myfile.eof() )
{
getline (myfile,line);
int i = 0;
string s;
int index = 0;
while(line[i] != '')
{
s[index] = line[i];
i++;
index++;
}
cout << s << endl;
}
myfile.close();
}
else cout << "Unable to open file";
return 0;
}
im then going to return the vector entries into a class.
Comment