I want to put some text from a text file into an array, but have the text in the array as individual characters. How would I do that?
目前我有
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <vector>
#include <sstream>
using namespace std;
int main()
{
string line;
ifstream myfile ("maze.txt");
if (myfile.is_open())
{
while ( myfile.good() )
{
getline (myfile,line);
// --------------------------------------
string s(line);
istringstream iss(s);
do
{
string sub;
iss >> sub;
cout << "Substring: " << sub << endl;
} while (iss);
// ---------------------------------------------
}
myfile.close();
}
else cout << "Unable to open file";
system ("pause");
return 0;
}
I m guessing getline gets one line at a time. Now how would I split that line into individual characters, and then put those characters in an array? I am taking a C++ course for the first time so I m new, be nice :p