osx - Opening 2 data files with C++ -


i wrote program create gnuplot commands according data read input file. required far many commands hand. worked quite nicely, need read data 2 different data files , use these create gnuplot commands. unfortunately seems going wrong reading of 2 files. portion of code involved in reading data files follows:

#include <iostream> #include <fstream> #include <sstream>  using namespace std;  int n_snapshots;  int main () {      std::cout << "enter number of snapshots" << "\n";     std::cin >> n_snapshots;      int snap_cell_count[n_snapshots];      std::ifstream in_file_count("data/snapshot_data");     std::ifstream in_file_fates("data/cell_fates_data_final");      (int i=0; i<n_snapshots; i++) {         in_file_count >> snap_cell_count[i];     }     in_file_count.close();      int cell_fates[snap_cell_count[n_snapshots-1]];     (int i=0; i<snap_cell_count[n_snapshots-1]; i++) {         in_file_fates >> cell_fates[i];     }     in_file_fates.close();  

n_snapshots integer, snap_cell_count[] array "n_shapshots" elements, each of takes value read data file "snapshot_data". cell_fates[] array number of elements equal value of last element in snap_cell_count[], , again values of elements read file, in case "cell_fates_data_final". data files read stored in folder called "data".

unfortunately, compiler returns following errors.

undefined symbols architecture x86_64:   "std::basic_string<char, std::char_traits<char>, std::allocator<char> >::c_str() const", referenced from:   _main in ccrpsav5.o   "std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::str() const", referenced from:   _main in ccrpsav5.o   "std::basic_istream<char, std::char_traits<char> >::operator>>(int&)", referenced from:   _main in ccrpsav5.o   "std::basic_ostream<char, std::char_traits<char> >::operator<<(int)", referenced from:   _main in ccrpsav5.o   "std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()", referenced from:   _main in ccrpsav5.o   "std::basic_ifstream<char, std::char_traits<char> >::close()", referenced from:   _main in ccrpsav5.o   "std::basic_ifstream<char, std::char_traits<char> >::basic_ifstream(char const*, std::_ios_openmode)", referenced from:   _main in ccrpsav5.o   "std::basic_ifstream<char, std::char_traits<char> >::~basic_ifstream()", referenced from:   _main in ccrpsav5.o   "std::basic_ofstream<char, std::char_traits<char> >::open(char const*, std::_ios_openmode)", referenced from:   _main in ccrpsav5.o   "std::basic_ofstream<char, std::char_traits<char> >::close()", referenced from:   _main in ccrpsav5.o   "std::basic_ofstream<char, std::char_traits<char> >::basic_ofstream()", referenced from:   _main in ccrpsav5.o   "std::basic_ofstream<char, std::char_traits<char> >::~basic_ofstream()", referenced from:   _main in ccrpsav5.o   "std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::basic_stringstream(std::_ios_openmode)", referenced from:   _main in ccrpsav5.o   "std::basic_stringstream<char, std::char_traits<char>, std::allocator<char> >::~basic_stringstream()", referenced from:   _main in ccrpsav5.o   "std::ios_base::init::init()", referenced from:   __static_initialization_and_destruction_0(int, int) in ccrpsav5.o   "std::ios_base::init::~init()", referenced from:   __static_initialization_and_destruction_0(int, int) in ccrpsav5.o   "std::cin", referenced from:   _main in ccrpsav5.o   "std::cout", referenced from:   _main in ccrpsav5.o   "std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)", referenced from:   _main in ccrpsav5.o   "___gxx_personality_v0", referenced from:   dwarf exception unwind info (__eh_frame) in ccrpsav5.o ld: symbol(s) not found architecture x86_64 collect2: error: ld returned 1 exit status 

this being compiled gcc compiler on mac osx mountain lion.

does have idea what's wrong here?

well, starters can't int snap_cell_count[n_snapshots] value of n_snapshots being determined @ runtime. have like

int *snap_cell_count = new int[n_snapshots]; // stuff delete[] snap_cell_count; 

same thing cell_fates

as linker errors, maybe this question solves issues...


Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

jquery - How would i go about shortening this code? And to cancel the previous click on click of new section? -