for (j=0;j<cols; j++)
cout<<dynamicArray [0][j]<<"||";//<--Help to improve the outlook so that the information may appear as if in a table. //i would like this row 0 column to be arranged horizontally and appears as if it is the first row of a table with the strings initialized above to appear as the respective column headings e.g.
//Row 1 ->User iput at runtime || User iput at runtime ||User iput at runtime||User iput at runtime ||User iput at runtime ||User iput at runtime ||User iput at runtime||User iput at runtime
//Row 2 -> User iput at runtime || User iput at runtime ||User iput at runtime||User iput at runtime ||User iput at runtime ||User iput at runtime ||User iput at runtime||User iput at runtime
cout<<endl<<"\n\n";
cout<<"Table headings (First row i.e Row 0 columns) have been displayed."; //checking compilation error...
cout<<endl<<"\n\n";
for (i=1; i<rows; i++) {
for (j=0;j<cols; j++){
cout<<"Enter details for proprietor/ owner:"<<(i+1)<<"in this record";
cin.getline(cin, reader); //to take user input into a string (reader) temporarily <---problem here. It has failed to take the input strings
dynamicArray [i].push_back(reader); //copy the contents of string array (reader) into the vector <---problem here. It has failed to take the input strings and enter it here.
rows--;
}
cout<<endl;
}
}
cout<<"You have entered this data:";
cout<<endl<<"\n\n";
for (i=0; i<rows; i++) {
for (j=0; j<cols; j++){
cout<<dynamicArray[i][j]<<"||"; // prints the first row (row 0) at first, followed by the specific details in the creted rows below it. Remember, I would have liked it to be a table with first row columns as headings and specific details entered at runtime should start at row 1.
// LR_UNIT_NUMBER || NAME_OF_PROPRIETOR || NATIONAL_ID_CARD_NUMBER || ADDRESS_OF_PROPRIETOR || PIN_NUMBER_OF_PROPRIETOR || DATE_LAND_WAS_ACQUIRED || DATE_OF_ISSUE_OF_TITLE_DEED||
}
cout<<endl<<"\n\n";
cout<<"Record number: "<<(rows-1)<<" has been created"; //A counter...checking compilation error...
cout<<endl<<"\n\n";
}
system ("pause");
EXIT_SUCCESS;
}
ERROR THROWN
1>------ Build started: Project: 2D_vector, Configuration: Debug Win32 ------
1>Compiling...
1>myVector.cpp
1>.\myVector.cpp(68) : error C2664: 'std::basic_istream<_Elem,_Traits>&std::basic_istream<_Elem,_Traits>::getline(_Elem *,std::streamsize)' : cannot convert parameter 1 from 'std::istream' to 'char *'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>
1> ]
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>.\myVector.cpp(70) : error C2664: 'std::vector<_Ty>::push_back' : cannot convert parameter 1 from 'char' to 'const std::string &'
1> with
1> [
1> _Ty=std::string
1> ]
1> Reason: cannot convert from 'char' to 'const std::string'
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>Build log was saved at "file://c:\Users\dell\Documents\Visual Studio 2005\Projects\2D_vector\2D_vector\Debug\BuildLog.htm"
1>2D_vector - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Thanx big, JLBorges (7445) for your insight .
There are these six six errors the compiler (Visual C++) is throwing for your code. I am trying to understand them but cant get them, would you please correct them and put some commentaries in them please ? I am a student and still learning to code.
I thought the errors have something to do with the vector fld_names since the errors affect the parts where the fld_name variable has been used.
Code part 1:
for( const std::string tag : fld_names )
Code part 2:
const std::vector<std::string> fld_names { "unit number", "name of proprietor", "national id card number", "address of proprietor", "pin number of proprietor" /* etc.*/ } ;
Error message:
1>.\2D_vector.cpp(33) : error C2601: 'fld_names' : local function definitions are illegal
1>.\2D_vector.cpp(32): this line contains a '{' which has not yet been matched
1>.\2D_vector.cpp(34) : error C2143: syntax error : missing ';' before '}'
> There are these six six errors the compiler (Visual C++) is throwing for your code.
The errors ae being thrown by an obsolete version of the Microsoft compiler.
Update to the current version Visual Studio 2015 (the community edition is free) and the errors will go away.
> Code part 1: for( const std::string tag : fld_names )
Thanks soo much JLBorges even for the update. You are a great resource yourself ! I am on way to work and will keep in touch as i proceed with the project. Once again, thank you.
I am now working on outputting this data to a text file.
Also reading from the text file during runtime (sort of writing to a database but in this case a text file e.g "Land_register.txt") and then reading the contents already in the register.
for( std::size_t i = 0 ; i < data_set.size() ; ++i )
myregister<<data_set [i]; // i may not be correct here.
Kindly demonstrate how to do this for the above code you guided, i would much appreciate.
Finally, what is the syntax for searching for a SPECIFIC record/ data e.g. a person's name that has been entered into the "Land_register.txt", without reading the whole data entered into the register ?
And is it possible to read the whole of this data in the register at once (i.e. opening and displaying the whole register) ? Is there an implementation (may be using fstream) that can be written to output this data to an accessory device e.g. printer for hardcopy printing ?