C++: ifstream as a parameter
I'm trying to make a program that will be able to both create a .txt file and reads from it to create output for tic-tac-toe meant for Linux. However, one of my functions is not initializing it's first parameter, the input stream from the file in question, in order to create the output needed.
The function prototype:
void loadSquaresFromStream( ifstream inStream, char statusSquare, int currGame, int
row, int column, int mark, int player, int games_Left );
// This function reads from the file 'games.txt' and uses it to update the array
// used to output each game.
The function head and body:
void loadSquaresFromStream( ifstream inStream, char statusSquare, int currGame, int
row, int column, int mark, int player, int games_Left ) {
while ( currGame == 1 ) {
inStream >> row >> column;
if ( row == 1 && column == 1 && statusSquare[1] == ' ' ) {
statusSquare[1] = mark;
player++;
}
else if ( row == 1 && column == 2 && statusSquare[2] == ' ' ) {
statusSquare[2] = mark;
player++;
}
else if ( row == 1 && column == 3 && statusSquare[3] == ' ' ) {
statusSquare[3] = mark;
player++;
....
....
else if ( row == 0 && column == 0 ) {
currGame = 0;
}
else {
currGame = 0;
games_Left = 0;
}
}
}
And the area in the main function:
int main() {
....
....
else if ( option == '2' ) { //line 189
cout << " Checking for file 'games.txt' in current directory... " << endl;
inStream.open ( "games.txt" );
if ( inStream.fail( )) {
cout << " ERROR: File 'games.txt' was not found. Please re-execute this program and play a game to create the file before using this feature. " << endl;
exit(1);
}
else {
cout << " File 'games.txt' found. Displaying output now. " << endl << endl;
}
system( "cls" );
while ( games_Left == 1 ) {
cout << "Board Positions for Game " << games << ": " << endl;
loadSquaresFromStream( inStream, statusSquare, currGame, row, column, mark, player, games_Left); //line 202
....
....
}
This is the error syntax I got while trying to compile from cygwin and code::blocks.
In file included from /usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/ios:42:0,
from /usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/ostream:38,
from /usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/iostream:39,
from jebecker_assignment01.cpp:16:
/usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/bits/ios_base.h: In copy constructor ‘std::basic_ios<char>::basic_ios(const std::basic_ios<char>&)’:
/usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/bits/ios_base.h:786:5: error: ‘std::ios_base::ios_base(const std::ios_base&)’ is private
ios_base(const ios_base&);
^
In file included from /usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/ios:44:0,
from /usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/ostream:38,
from /usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/iostream:39,
from jebecker_assignment01.cpp:16:
/usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/bits/basic_ios.h:66:11: error: within this context
class basic_ios : public ios_base
^
In file included from jebecker_assignment01.cpp:17:0:
/usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/fstream: In copy constructor ‘std::basic_ifstream<char>::basic_ifstream(const std::basic_ifstream<char>&)’:
/usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/fstream:427:11: note: synthesized method ‘std::basic_ios<char>::basic_ios(const std::basic_ios<char>&)’ first required here
class basic_ifstream : public basic_istream<_CharT, _Traits>
^
In file included from /usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/ios:43:0,
from /usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/ostream:38,
from /usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/iostream:39,
from jebecker_assignment01.cpp:16:
/usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/streambuf: In copy constructor ‘std::basic_filebuf<char>::basic_filebuf(const std::basic_filebuf<char>&)’:
/usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/streambuf:802:7: error: ‘std::basic_streambuf<_CharT, _Traits>::basic_streambuf(const std::basic_streambuf<_CharT, _Traits>&) [with _CharT = char; _Traits = std::char_traits<char>]’ is private
basic_streambuf(const basic_streambuf& __sb)
^
In file included from jebecker_assignment01.cpp:17:0:
/usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/fstream:72:11: error: within this context
class basic_filebuf : public basic_streambuf<_CharT, _Traits>
^
/usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/fstream: In copy constructor ‘std::basic_ifstream<char>::basic_ifstream(const std::basic_ifstream<char>&)’:
/usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/fstream:427:11: note: synthesized method ‘std::basic_filebuf<char>::basic_filebuf(const std::basic_filebuf<char>&)’ first required here
class basic_ifstream : public basic_istream<_CharT, _Traits>
^
jebecker_assignment01.cpp: In function ‘int main()’:
jebecker_assignment01.cpp:202:98: note: synthesized method ‘std::basic_ifstream<char>::basic_ifstream(const std::basic_ifstream<char>&)’ first required here
loadSquaresFromStream( inStream, statusSquare, currGame, row, column, mark, player, games_Left);
^
jebecker_assignment01.cpp:31:6: error: initializing argument 1 of ‘void loadSquaresFromStream(std::ifstream, char*, int, int, int, int, int, int)’
void loadSquaresFromStream( ifstream inStream, char statusSquare, int currGame, int row, int column, int mark, int player, int games_Left );
^
Could anyone figure out what's going wrong with the program?
EDIT: After changing ifstream to a call by reference, I got this when I tried to compile:
/tmp/ccM1q9XN.o:jebecker_assignment01.cpp:(.text+0x416): undefined reference to `displayActiveBoard()'
/tmp/ccM1q9XN.o:jebecker_assignment01.cpp:(.text+0xaf5): undefined reference to `checkActiveGameStatus()'
/tmp/ccM1q9XN.o:jebecker_assignment01.cpp:(.text+0xb17): undefined reference to `displayActiveBoard()'
/usr/lib/gcc/i686-pc-cygwin/4.8.2/../../../../i686-pc-cygwin/bin/ld: /tmp/ccM1q9XN.o: bad reloc address 0x0 in section `.ctors'
collect2: error: ld returned 1 exit status
Is this related to how I wrote my other functions, or is it because 'games.txt' does not exist yet?
c++ ifstream
add a comment |
I'm trying to make a program that will be able to both create a .txt file and reads from it to create output for tic-tac-toe meant for Linux. However, one of my functions is not initializing it's first parameter, the input stream from the file in question, in order to create the output needed.
The function prototype:
void loadSquaresFromStream( ifstream inStream, char statusSquare, int currGame, int
row, int column, int mark, int player, int games_Left );
// This function reads from the file 'games.txt' and uses it to update the array
// used to output each game.
The function head and body:
void loadSquaresFromStream( ifstream inStream, char statusSquare, int currGame, int
row, int column, int mark, int player, int games_Left ) {
while ( currGame == 1 ) {
inStream >> row >> column;
if ( row == 1 && column == 1 && statusSquare[1] == ' ' ) {
statusSquare[1] = mark;
player++;
}
else if ( row == 1 && column == 2 && statusSquare[2] == ' ' ) {
statusSquare[2] = mark;
player++;
}
else if ( row == 1 && column == 3 && statusSquare[3] == ' ' ) {
statusSquare[3] = mark;
player++;
....
....
else if ( row == 0 && column == 0 ) {
currGame = 0;
}
else {
currGame = 0;
games_Left = 0;
}
}
}
And the area in the main function:
int main() {
....
....
else if ( option == '2' ) { //line 189
cout << " Checking for file 'games.txt' in current directory... " << endl;
inStream.open ( "games.txt" );
if ( inStream.fail( )) {
cout << " ERROR: File 'games.txt' was not found. Please re-execute this program and play a game to create the file before using this feature. " << endl;
exit(1);
}
else {
cout << " File 'games.txt' found. Displaying output now. " << endl << endl;
}
system( "cls" );
while ( games_Left == 1 ) {
cout << "Board Positions for Game " << games << ": " << endl;
loadSquaresFromStream( inStream, statusSquare, currGame, row, column, mark, player, games_Left); //line 202
....
....
}
This is the error syntax I got while trying to compile from cygwin and code::blocks.
In file included from /usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/ios:42:0,
from /usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/ostream:38,
from /usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/iostream:39,
from jebecker_assignment01.cpp:16:
/usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/bits/ios_base.h: In copy constructor ‘std::basic_ios<char>::basic_ios(const std::basic_ios<char>&)’:
/usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/bits/ios_base.h:786:5: error: ‘std::ios_base::ios_base(const std::ios_base&)’ is private
ios_base(const ios_base&);
^
In file included from /usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/ios:44:0,
from /usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/ostream:38,
from /usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/iostream:39,
from jebecker_assignment01.cpp:16:
/usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/bits/basic_ios.h:66:11: error: within this context
class basic_ios : public ios_base
^
In file included from jebecker_assignment01.cpp:17:0:
/usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/fstream: In copy constructor ‘std::basic_ifstream<char>::basic_ifstream(const std::basic_ifstream<char>&)’:
/usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/fstream:427:11: note: synthesized method ‘std::basic_ios<char>::basic_ios(const std::basic_ios<char>&)’ first required here
class basic_ifstream : public basic_istream<_CharT, _Traits>
^
In file included from /usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/ios:43:0,
from /usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/ostream:38,
from /usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/iostream:39,
from jebecker_assignment01.cpp:16:
/usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/streambuf: In copy constructor ‘std::basic_filebuf<char>::basic_filebuf(const std::basic_filebuf<char>&)’:
/usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/streambuf:802:7: error: ‘std::basic_streambuf<_CharT, _Traits>::basic_streambuf(const std::basic_streambuf<_CharT, _Traits>&) [with _CharT = char; _Traits = std::char_traits<char>]’ is private
basic_streambuf(const basic_streambuf& __sb)
^
In file included from jebecker_assignment01.cpp:17:0:
/usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/fstream:72:11: error: within this context
class basic_filebuf : public basic_streambuf<_CharT, _Traits>
^
/usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/fstream: In copy constructor ‘std::basic_ifstream<char>::basic_ifstream(const std::basic_ifstream<char>&)’:
/usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/fstream:427:11: note: synthesized method ‘std::basic_filebuf<char>::basic_filebuf(const std::basic_filebuf<char>&)’ first required here
class basic_ifstream : public basic_istream<_CharT, _Traits>
^
jebecker_assignment01.cpp: In function ‘int main()’:
jebecker_assignment01.cpp:202:98: note: synthesized method ‘std::basic_ifstream<char>::basic_ifstream(const std::basic_ifstream<char>&)’ first required here
loadSquaresFromStream( inStream, statusSquare, currGame, row, column, mark, player, games_Left);
^
jebecker_assignment01.cpp:31:6: error: initializing argument 1 of ‘void loadSquaresFromStream(std::ifstream, char*, int, int, int, int, int, int)’
void loadSquaresFromStream( ifstream inStream, char statusSquare, int currGame, int row, int column, int mark, int player, int games_Left );
^
Could anyone figure out what's going wrong with the program?
EDIT: After changing ifstream to a call by reference, I got this when I tried to compile:
/tmp/ccM1q9XN.o:jebecker_assignment01.cpp:(.text+0x416): undefined reference to `displayActiveBoard()'
/tmp/ccM1q9XN.o:jebecker_assignment01.cpp:(.text+0xaf5): undefined reference to `checkActiveGameStatus()'
/tmp/ccM1q9XN.o:jebecker_assignment01.cpp:(.text+0xb17): undefined reference to `displayActiveBoard()'
/usr/lib/gcc/i686-pc-cygwin/4.8.2/../../../../i686-pc-cygwin/bin/ld: /tmp/ccM1q9XN.o: bad reloc address 0x0 in section `.ctors'
collect2: error: ld returned 1 exit status
Is this related to how I wrote my other functions, or is it because 'games.txt' does not exist yet?
c++ ifstream
add a comment |
I'm trying to make a program that will be able to both create a .txt file and reads from it to create output for tic-tac-toe meant for Linux. However, one of my functions is not initializing it's first parameter, the input stream from the file in question, in order to create the output needed.
The function prototype:
void loadSquaresFromStream( ifstream inStream, char statusSquare, int currGame, int
row, int column, int mark, int player, int games_Left );
// This function reads from the file 'games.txt' and uses it to update the array
// used to output each game.
The function head and body:
void loadSquaresFromStream( ifstream inStream, char statusSquare, int currGame, int
row, int column, int mark, int player, int games_Left ) {
while ( currGame == 1 ) {
inStream >> row >> column;
if ( row == 1 && column == 1 && statusSquare[1] == ' ' ) {
statusSquare[1] = mark;
player++;
}
else if ( row == 1 && column == 2 && statusSquare[2] == ' ' ) {
statusSquare[2] = mark;
player++;
}
else if ( row == 1 && column == 3 && statusSquare[3] == ' ' ) {
statusSquare[3] = mark;
player++;
....
....
else if ( row == 0 && column == 0 ) {
currGame = 0;
}
else {
currGame = 0;
games_Left = 0;
}
}
}
And the area in the main function:
int main() {
....
....
else if ( option == '2' ) { //line 189
cout << " Checking for file 'games.txt' in current directory... " << endl;
inStream.open ( "games.txt" );
if ( inStream.fail( )) {
cout << " ERROR: File 'games.txt' was not found. Please re-execute this program and play a game to create the file before using this feature. " << endl;
exit(1);
}
else {
cout << " File 'games.txt' found. Displaying output now. " << endl << endl;
}
system( "cls" );
while ( games_Left == 1 ) {
cout << "Board Positions for Game " << games << ": " << endl;
loadSquaresFromStream( inStream, statusSquare, currGame, row, column, mark, player, games_Left); //line 202
....
....
}
This is the error syntax I got while trying to compile from cygwin and code::blocks.
In file included from /usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/ios:42:0,
from /usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/ostream:38,
from /usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/iostream:39,
from jebecker_assignment01.cpp:16:
/usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/bits/ios_base.h: In copy constructor ‘std::basic_ios<char>::basic_ios(const std::basic_ios<char>&)’:
/usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/bits/ios_base.h:786:5: error: ‘std::ios_base::ios_base(const std::ios_base&)’ is private
ios_base(const ios_base&);
^
In file included from /usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/ios:44:0,
from /usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/ostream:38,
from /usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/iostream:39,
from jebecker_assignment01.cpp:16:
/usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/bits/basic_ios.h:66:11: error: within this context
class basic_ios : public ios_base
^
In file included from jebecker_assignment01.cpp:17:0:
/usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/fstream: In copy constructor ‘std::basic_ifstream<char>::basic_ifstream(const std::basic_ifstream<char>&)’:
/usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/fstream:427:11: note: synthesized method ‘std::basic_ios<char>::basic_ios(const std::basic_ios<char>&)’ first required here
class basic_ifstream : public basic_istream<_CharT, _Traits>
^
In file included from /usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/ios:43:0,
from /usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/ostream:38,
from /usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/iostream:39,
from jebecker_assignment01.cpp:16:
/usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/streambuf: In copy constructor ‘std::basic_filebuf<char>::basic_filebuf(const std::basic_filebuf<char>&)’:
/usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/streambuf:802:7: error: ‘std::basic_streambuf<_CharT, _Traits>::basic_streambuf(const std::basic_streambuf<_CharT, _Traits>&) [with _CharT = char; _Traits = std::char_traits<char>]’ is private
basic_streambuf(const basic_streambuf& __sb)
^
In file included from jebecker_assignment01.cpp:17:0:
/usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/fstream:72:11: error: within this context
class basic_filebuf : public basic_streambuf<_CharT, _Traits>
^
/usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/fstream: In copy constructor ‘std::basic_ifstream<char>::basic_ifstream(const std::basic_ifstream<char>&)’:
/usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/fstream:427:11: note: synthesized method ‘std::basic_filebuf<char>::basic_filebuf(const std::basic_filebuf<char>&)’ first required here
class basic_ifstream : public basic_istream<_CharT, _Traits>
^
jebecker_assignment01.cpp: In function ‘int main()’:
jebecker_assignment01.cpp:202:98: note: synthesized method ‘std::basic_ifstream<char>::basic_ifstream(const std::basic_ifstream<char>&)’ first required here
loadSquaresFromStream( inStream, statusSquare, currGame, row, column, mark, player, games_Left);
^
jebecker_assignment01.cpp:31:6: error: initializing argument 1 of ‘void loadSquaresFromStream(std::ifstream, char*, int, int, int, int, int, int)’
void loadSquaresFromStream( ifstream inStream, char statusSquare, int currGame, int row, int column, int mark, int player, int games_Left );
^
Could anyone figure out what's going wrong with the program?
EDIT: After changing ifstream to a call by reference, I got this when I tried to compile:
/tmp/ccM1q9XN.o:jebecker_assignment01.cpp:(.text+0x416): undefined reference to `displayActiveBoard()'
/tmp/ccM1q9XN.o:jebecker_assignment01.cpp:(.text+0xaf5): undefined reference to `checkActiveGameStatus()'
/tmp/ccM1q9XN.o:jebecker_assignment01.cpp:(.text+0xb17): undefined reference to `displayActiveBoard()'
/usr/lib/gcc/i686-pc-cygwin/4.8.2/../../../../i686-pc-cygwin/bin/ld: /tmp/ccM1q9XN.o: bad reloc address 0x0 in section `.ctors'
collect2: error: ld returned 1 exit status
Is this related to how I wrote my other functions, or is it because 'games.txt' does not exist yet?
c++ ifstream
I'm trying to make a program that will be able to both create a .txt file and reads from it to create output for tic-tac-toe meant for Linux. However, one of my functions is not initializing it's first parameter, the input stream from the file in question, in order to create the output needed.
The function prototype:
void loadSquaresFromStream( ifstream inStream, char statusSquare, int currGame, int
row, int column, int mark, int player, int games_Left );
// This function reads from the file 'games.txt' and uses it to update the array
// used to output each game.
The function head and body:
void loadSquaresFromStream( ifstream inStream, char statusSquare, int currGame, int
row, int column, int mark, int player, int games_Left ) {
while ( currGame == 1 ) {
inStream >> row >> column;
if ( row == 1 && column == 1 && statusSquare[1] == ' ' ) {
statusSquare[1] = mark;
player++;
}
else if ( row == 1 && column == 2 && statusSquare[2] == ' ' ) {
statusSquare[2] = mark;
player++;
}
else if ( row == 1 && column == 3 && statusSquare[3] == ' ' ) {
statusSquare[3] = mark;
player++;
....
....
else if ( row == 0 && column == 0 ) {
currGame = 0;
}
else {
currGame = 0;
games_Left = 0;
}
}
}
And the area in the main function:
int main() {
....
....
else if ( option == '2' ) { //line 189
cout << " Checking for file 'games.txt' in current directory... " << endl;
inStream.open ( "games.txt" );
if ( inStream.fail( )) {
cout << " ERROR: File 'games.txt' was not found. Please re-execute this program and play a game to create the file before using this feature. " << endl;
exit(1);
}
else {
cout << " File 'games.txt' found. Displaying output now. " << endl << endl;
}
system( "cls" );
while ( games_Left == 1 ) {
cout << "Board Positions for Game " << games << ": " << endl;
loadSquaresFromStream( inStream, statusSquare, currGame, row, column, mark, player, games_Left); //line 202
....
....
}
This is the error syntax I got while trying to compile from cygwin and code::blocks.
In file included from /usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/ios:42:0,
from /usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/ostream:38,
from /usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/iostream:39,
from jebecker_assignment01.cpp:16:
/usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/bits/ios_base.h: In copy constructor ‘std::basic_ios<char>::basic_ios(const std::basic_ios<char>&)’:
/usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/bits/ios_base.h:786:5: error: ‘std::ios_base::ios_base(const std::ios_base&)’ is private
ios_base(const ios_base&);
^
In file included from /usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/ios:44:0,
from /usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/ostream:38,
from /usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/iostream:39,
from jebecker_assignment01.cpp:16:
/usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/bits/basic_ios.h:66:11: error: within this context
class basic_ios : public ios_base
^
In file included from jebecker_assignment01.cpp:17:0:
/usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/fstream: In copy constructor ‘std::basic_ifstream<char>::basic_ifstream(const std::basic_ifstream<char>&)’:
/usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/fstream:427:11: note: synthesized method ‘std::basic_ios<char>::basic_ios(const std::basic_ios<char>&)’ first required here
class basic_ifstream : public basic_istream<_CharT, _Traits>
^
In file included from /usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/ios:43:0,
from /usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/ostream:38,
from /usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/iostream:39,
from jebecker_assignment01.cpp:16:
/usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/streambuf: In copy constructor ‘std::basic_filebuf<char>::basic_filebuf(const std::basic_filebuf<char>&)’:
/usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/streambuf:802:7: error: ‘std::basic_streambuf<_CharT, _Traits>::basic_streambuf(const std::basic_streambuf<_CharT, _Traits>&) [with _CharT = char; _Traits = std::char_traits<char>]’ is private
basic_streambuf(const basic_streambuf& __sb)
^
In file included from jebecker_assignment01.cpp:17:0:
/usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/fstream:72:11: error: within this context
class basic_filebuf : public basic_streambuf<_CharT, _Traits>
^
/usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/fstream: In copy constructor ‘std::basic_ifstream<char>::basic_ifstream(const std::basic_ifstream<char>&)’:
/usr/lib/gcc/i686-pc-cygwin/4.8.2/include/c++/fstream:427:11: note: synthesized method ‘std::basic_filebuf<char>::basic_filebuf(const std::basic_filebuf<char>&)’ first required here
class basic_ifstream : public basic_istream<_CharT, _Traits>
^
jebecker_assignment01.cpp: In function ‘int main()’:
jebecker_assignment01.cpp:202:98: note: synthesized method ‘std::basic_ifstream<char>::basic_ifstream(const std::basic_ifstream<char>&)’ first required here
loadSquaresFromStream( inStream, statusSquare, currGame, row, column, mark, player, games_Left);
^
jebecker_assignment01.cpp:31:6: error: initializing argument 1 of ‘void loadSquaresFromStream(std::ifstream, char*, int, int, int, int, int, int)’
void loadSquaresFromStream( ifstream inStream, char statusSquare, int currGame, int row, int column, int mark, int player, int games_Left );
^
Could anyone figure out what's going wrong with the program?
EDIT: After changing ifstream to a call by reference, I got this when I tried to compile:
/tmp/ccM1q9XN.o:jebecker_assignment01.cpp:(.text+0x416): undefined reference to `displayActiveBoard()'
/tmp/ccM1q9XN.o:jebecker_assignment01.cpp:(.text+0xaf5): undefined reference to `checkActiveGameStatus()'
/tmp/ccM1q9XN.o:jebecker_assignment01.cpp:(.text+0xb17): undefined reference to `displayActiveBoard()'
/usr/lib/gcc/i686-pc-cygwin/4.8.2/../../../../i686-pc-cygwin/bin/ld: /tmp/ccM1q9XN.o: bad reloc address 0x0 in section `.ctors'
collect2: error: ld returned 1 exit status
Is this related to how I wrote my other functions, or is it because 'games.txt' does not exist yet?
c++ ifstream
c++ ifstream
edited Mar 5 '14 at 4:44
JbstormburstADV
asked Mar 5 '14 at 4:22
JbstormburstADVJbstormburstADV
165
165
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
ifstream
objects can't be copied. Pass by reference instead.
Could you mention how to do this? I'm a bit shaky in my parameters.
– JbstormburstADV
Mar 5 '14 at 4:25
1
ifstream &inStream
– timrau
Mar 5 '14 at 4:25
I add this where I call for the function, right? Also, what primary do I use, or is that something else?
– JbstormburstADV
Mar 5 '14 at 4:26
No. Add the&
in parameter list when you declare and defineloadSquaresFromStream()
.
– timrau
Mar 5 '14 at 4:28
OK, did that, and now I'm getting undefined references in three of my functions. Is this related, or am I looking at something new?
– JbstormburstADV
Mar 5 '14 at 4:41
|
show 5 more comments
You can't pass an ifstream
by value: it's not copyable.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f22188476%2fc-ifstream-as-a-parameter%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
ifstream
objects can't be copied. Pass by reference instead.
Could you mention how to do this? I'm a bit shaky in my parameters.
– JbstormburstADV
Mar 5 '14 at 4:25
1
ifstream &inStream
– timrau
Mar 5 '14 at 4:25
I add this where I call for the function, right? Also, what primary do I use, or is that something else?
– JbstormburstADV
Mar 5 '14 at 4:26
No. Add the&
in parameter list when you declare and defineloadSquaresFromStream()
.
– timrau
Mar 5 '14 at 4:28
OK, did that, and now I'm getting undefined references in three of my functions. Is this related, or am I looking at something new?
– JbstormburstADV
Mar 5 '14 at 4:41
|
show 5 more comments
ifstream
objects can't be copied. Pass by reference instead.
Could you mention how to do this? I'm a bit shaky in my parameters.
– JbstormburstADV
Mar 5 '14 at 4:25
1
ifstream &inStream
– timrau
Mar 5 '14 at 4:25
I add this where I call for the function, right? Also, what primary do I use, or is that something else?
– JbstormburstADV
Mar 5 '14 at 4:26
No. Add the&
in parameter list when you declare and defineloadSquaresFromStream()
.
– timrau
Mar 5 '14 at 4:28
OK, did that, and now I'm getting undefined references in three of my functions. Is this related, or am I looking at something new?
– JbstormburstADV
Mar 5 '14 at 4:41
|
show 5 more comments
ifstream
objects can't be copied. Pass by reference instead.
ifstream
objects can't be copied. Pass by reference instead.
answered Mar 5 '14 at 4:23
BrianBrian
64.2k795182
64.2k795182
Could you mention how to do this? I'm a bit shaky in my parameters.
– JbstormburstADV
Mar 5 '14 at 4:25
1
ifstream &inStream
– timrau
Mar 5 '14 at 4:25
I add this where I call for the function, right? Also, what primary do I use, or is that something else?
– JbstormburstADV
Mar 5 '14 at 4:26
No. Add the&
in parameter list when you declare and defineloadSquaresFromStream()
.
– timrau
Mar 5 '14 at 4:28
OK, did that, and now I'm getting undefined references in three of my functions. Is this related, or am I looking at something new?
– JbstormburstADV
Mar 5 '14 at 4:41
|
show 5 more comments
Could you mention how to do this? I'm a bit shaky in my parameters.
– JbstormburstADV
Mar 5 '14 at 4:25
1
ifstream &inStream
– timrau
Mar 5 '14 at 4:25
I add this where I call for the function, right? Also, what primary do I use, or is that something else?
– JbstormburstADV
Mar 5 '14 at 4:26
No. Add the&
in parameter list when you declare and defineloadSquaresFromStream()
.
– timrau
Mar 5 '14 at 4:28
OK, did that, and now I'm getting undefined references in three of my functions. Is this related, or am I looking at something new?
– JbstormburstADV
Mar 5 '14 at 4:41
Could you mention how to do this? I'm a bit shaky in my parameters.
– JbstormburstADV
Mar 5 '14 at 4:25
Could you mention how to do this? I'm a bit shaky in my parameters.
– JbstormburstADV
Mar 5 '14 at 4:25
1
1
ifstream &inStream
– timrau
Mar 5 '14 at 4:25
ifstream &inStream
– timrau
Mar 5 '14 at 4:25
I add this where I call for the function, right? Also, what primary do I use, or is that something else?
– JbstormburstADV
Mar 5 '14 at 4:26
I add this where I call for the function, right? Also, what primary do I use, or is that something else?
– JbstormburstADV
Mar 5 '14 at 4:26
No. Add the
&
in parameter list when you declare and define loadSquaresFromStream()
.– timrau
Mar 5 '14 at 4:28
No. Add the
&
in parameter list when you declare and define loadSquaresFromStream()
.– timrau
Mar 5 '14 at 4:28
OK, did that, and now I'm getting undefined references in three of my functions. Is this related, or am I looking at something new?
– JbstormburstADV
Mar 5 '14 at 4:41
OK, did that, and now I'm getting undefined references in three of my functions. Is this related, or am I looking at something new?
– JbstormburstADV
Mar 5 '14 at 4:41
|
show 5 more comments
You can't pass an ifstream
by value: it's not copyable.
add a comment |
You can't pass an ifstream
by value: it's not copyable.
add a comment |
You can't pass an ifstream
by value: it's not copyable.
You can't pass an ifstream
by value: it's not copyable.
answered Mar 5 '14 at 4:23
Cheers and hth. - AlfCheers and hth. - Alf
123k11160265
123k11160265
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f22188476%2fc-ifstream-as-a-parameter%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown