G
Gaurav
Hello
I have a program that basically inverts the contents of files except
first line.
It compiles fine but gives me core dump on running. If i comment
temp.clear() it runs fine, but i need it to clear the temp vector for
each file.
********************* code *******************
#include <fstream>
#include <string>
#include <vector>
#include <iostream>
using namespace std;
// This program just inverts the tickers.csv files execpt first line
int main(){
string ticker, line;
string input,output;
ifstream Tickers( "tickers.txt", ios::in);
ifstream Input_File;
ofstream Output_File;
vector <string> temp;
while(Tickers>>ticker){
input = "tempdata/" + ticker + ".csv";
output = "tempdata/" + ticker + "1.csv";
Input_File.open( input.c_str(), ios::in);
Output_File.open ( output.c_str(), ios::app);
while ( Input_File >> line ){
temp.push_back(line);
}
Output_File << temp[0] << endl;
for ( unsigned i = ( temp.size() - 1 ); i > 0; i--)
Output_File << temp << endl;
Input_File.close();
Output_File.close();
temp.clear();
}
return 0;
}
***************************************
tickers.txt contains part of file name. tempdata is a subdirectory. i
have the files to be inverted present in tempdata.
thank you in advance.
I have a program that basically inverts the contents of files except
first line.
It compiles fine but gives me core dump on running. If i comment
temp.clear() it runs fine, but i need it to clear the temp vector for
each file.
********************* code *******************
#include <fstream>
#include <string>
#include <vector>
#include <iostream>
using namespace std;
// This program just inverts the tickers.csv files execpt first line
int main(){
string ticker, line;
string input,output;
ifstream Tickers( "tickers.txt", ios::in);
ifstream Input_File;
ofstream Output_File;
vector <string> temp;
while(Tickers>>ticker){
input = "tempdata/" + ticker + ".csv";
output = "tempdata/" + ticker + "1.csv";
Input_File.open( input.c_str(), ios::in);
Output_File.open ( output.c_str(), ios::app);
while ( Input_File >> line ){
temp.push_back(line);
}
Output_File << temp[0] << endl;
for ( unsigned i = ( temp.size() - 1 ); i > 0; i--)
Output_File << temp << endl;
Input_File.close();
Output_File.close();
temp.clear();
}
return 0;
}
***************************************
tickers.txt contains part of file name. tempdata is a subdirectory. i
have the files to be inverted present in tempdata.
thank you in advance.