EDIT: This has been fixed. I instead just created a stringstream buffer and filled out the strings that way instead of doing it on one line. Guess I should had known that their compiler doesn't support this yet...
Yes this is a school assignment that I was going to go ahead and try to compile on the schools compilers just to make sure all the test cases and everything were met before I started to clean the code up for the final submission. Though it fails compiling on the schools submission compiler pretty bad.
This was compiled with Visual Studio 2012 and it compilers perfectly with absolutely zero warnings. When using the schools submission compiler (was never told what compiler it is using) it had brought up errors like the following:
Main.cpp: In function 'void Add(std::string, Student*, unsigned int&)':
Main.cpp:94:35: error: no match for 'operator>>' in 'std::basic_stringstream((*(const __string_type*)(& properties)), std::operator|((std::_Ios_Openmode)16u, (std::_Ios_Openmode)8u)) >> firstName'
Main.cpp:94:35: note: candidates are:
/usr/include/c++/4.6/istream:122:7: note: std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_istream<_CharT, _Traits>::__istream_type& (*)(std::basic_istream<_CharT, _Traits>::__istream_type&)) [with _CharT = char, _Traits = std::char_traits, std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream]
/usr/include/c++/4.6/istream:122:7: note: no known conversion for argument 1 from 'std::string {aka std::basic_string}' to 'std::basic_istream::__istream_type& (*)(std::basic_istream::__istream_type&) {aka std::basic_istream& (*)(std::basic_istream&)}'
/usr/include/c++/4.6/istream:126:7: note: std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_istream<_CharT, _Traits>::__ios_type& (*)(std::basic_istream<_CharT, _Traits>::__ios_type&)) [with _CharT = char, _Traits = std::char_traits, std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream, std::basic_istream<_CharT, _Traits>::__ios_type = std::basic_ios]
/usr/include/c++/4.6/istream:126:7: note: no known conversion for argument 1 from 'std::string {aka std::basic_string}' to 'std::basic_istream::__ios_type& (*)(std::basic_istream::__ios_type&) {aka std::basic_ios& (*)(std::basic_ios&)}'
/usr/include/c++/4.6/istream:133:7: note: std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(std::ios_base& (*)(std::ios_base&)) [with _CharT = char, _Traits = std::char_traits, std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream]
/usr/include/c++/4.6/istream:133:7: note: no known conversion for argument 1 from 'std::string {aka std::basic_string}' to 'std::ios_base& (*)(std::ios_base&)'
/usr/include/c++/4.6/istream:169:7: note: std::basic_istream<_CharT, _Traits>::__istream_type& std::basic_istream<_CharT, _Traits>::operator>>(bool&) [with _CharT = char, _Traits = std::char_traits, std::basic_istream<_CharT, _Traits>::__istream_type = std::basic_istream]
/usr/include/c++/4.6/istream:169:7: note: no known conversion for argument 1 from 'std::string {aka std::basic_string}' to 'bool&'
/usr/include/c++/4.6/istream:173:7: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(short int&) [with _CharT = char, _Traits = std::char_traits]
Here is the function it is complaining about:
void Add(std::string properties, Student theStudents[], unsigned int& numberElements)
{
// temporary attributes to read in from the properties string
std::string firstName, lastName, idNumber, classification, major;
// fill the attributes from the information in the properties string
std::stringstream(properties) >> firstName >> lastName >> idNumber >> classification >> major;
bool alreadyAdded = false;
// Only create the student if the idNumber is not already assigned
for(unsigned int i = 0; i<numberElements; i++)
{
if(idNumber == theStudents[i].GetProperty(Student::IdNumber))
{
std::cout << "Error! ID Number already assigned." <<std::endl;
alreadyAdded = true;
}
}
if(!alreadyAdded)
{
theStudents[numberElements].Create(firstName, lastName, idNumber, classification, major);
numberElements++;
}
}
Visual Studio 2012 has absolutely zero problem with this.
From the error it seems it does not like me to do this:
// fill the attributes from the information in the properties string
std::stringstream(properties) >> firstName >> lastName >> idNumber >> classification >> major;
Though I'm lost on why Visual Studio 2012 has no problem with that but their compiler absolutely hates that? Maybe I've always been wrong to do that really that's how I've always done it and not 100% sure of a clean solution to not do that.
Any ideas on why their compiler throws a fit about this but Visual Studio 2012 doesn't?
EDIT: I just tested it out using latest version of gcc and it complained about it also. What's Visual Studio 2012 compiler doing different here that it has zero problem? have I been using a C++11 feature of stringstream and actually not know it and the other compilers don't have that feature implemented yet? I'd appreciate any help here.
Thanks.
NOTE: The assignment doesn't have to deal with this command I/O, I've already implemented, tested, and finished the assignments major details.