Hi all, first post here so if I do anything against the rules of this community feel free to point that out.
Basically I'd have to write a very simple program that opens a .txt file, stores each word of each line into a "typedef vector<string> Tlinea" and each line into a "typedef vector<Tlinea> TTexto".
Using the Ttexto vector I should be able to print on screen the entire original text and to go through the text to find the blank spaces for each line.
I have written a program which gives the output expected using only the variable Ttlinea, however when I start using the Ttexto variable (part commented) all goes wrong.
This is my code:
Code:
#include <iostream>
#include <vector>
#include <fstream>
using namespace std;
typedef vector <string> TLinea;
typedef vector<TLinea> TTexto;
string line;
int main()
{
TLinea my_linea;
TTexto my_texto;
ifstream test ("Ejemplo.txt");
if(!test){
cout<<"Error opening output file"<<endl;
return 0;
}
while (getline(test,line)){
//for (int i = 0 ; i < my_linea.size(); i++){
my_linea.push_back(line);
cout << line ;
int total_blank_spaces = 0;
for (int t = 0; t < line.size(); t++){
if (line[t]== ' ') total_blank_spaces++;
}
cout << " ["Blank spaces: " << total_blank_spaces << "]";
cout << endl;
}
cout << endl;
/*Ttexto
my_texto.push_back(my_linea);
cout << my_texto[0] << endl;
*/
return 0;
}
Thanks in advance for any advice or possible solution.