This is the stack project I had to make. I'm posting my code after what the project is supposed to be. and then I'll post the error i get from compiling that i can't figure out.
What Project Is.
Project:
For this project you will write a program that will read in strings from a file named "reverse.in". Each word may be marked with an even number of "at" characters ('@'). The first '@' character signals that the following characters up to the next '@' are in reverse order. Your program will print the result to an output file called "reverse.out". You must use an STL stack to reverse the order of the characters.
For example, if the input file looks like this:
@egelloC@
CS174
re@srev@e
sup@ilacre@fragilist@ilaipxeci@docious
id@@en@@ti@@ty
then the output would be:
College
CS174
reverse
supercalifragilisticexpialidocious
identity
code i wrote
Code:
#include <stack>
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int i;
bool forward;
string word;
stack<char> letter;
string inFileName = "reverse.in";
string outFileName = "reverse.out";
ifstream inFile;
ofstream outFile;
inFile.open(inFileName.c_str());
outFile.open(outFileName.c_str());
forward = true;
inFile.getline(word);
while(inFile)
{
for(i=0;i<=word.length();i++)
{
if(forward)
{
outFile << word[i];
if(word[i] == '@')
{
forward = false;
}
}
else(!forward)
{
if(word[i]!='@')
{
letter.push(word[i])
}
else if(word[i] == '@')
{
forward = true;
while(!letter.empty)
{
outFile << letter.top();
letter.pop;
}
}
}
}
inFile.close();
outFile.close();
return 0;
};
the error i get from compiling
Code:
main.cpp: In function int main():
main.cpp:21: error: no matching function for call to std::basic_ifstream<char, std::char_traits<char> >::getline(std::string&)
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/istream:581: note: candidates are: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::getline(_CharT*, std::streamsize, _CharT) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/i486-linux-gnu/4.1.2/../../../../include/c++/4.1.2/istream:397: note: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::getline(_CharT*, std::streamsize) [with _CharT = char, _Traits = std::char_traits<char>]
main.cpp:35: error: expected `;' before { token
main.cpp:54: error: expected `}' at end of input
I looked at like 35 and line 54 but i have what the compiler is talking about, and I have no idea what the first error I have is. Thanks in advance.