hi guys please iv done my best involving few people already. program has to pick up words from 1file plikwe.txt, reverse them leaving a white spaces in a right places and then putting into plikwy.txt
it works a little bit different please guys help me adding a code dont tell what to do please and many thanks! :
include <cstdlib>
include <iostream>
include <fstream>
using namespace std;
int main (int argc,char *argv[])
{
const string delims("\t,.; ");
string line;
ifstream infile;
ofstream outfile;
for(int i=endIdx-1;i>=static_cast<int>(begIdx);--1) /*chce to zastapic czyms prostszym napisal mi to kto inny na moje mozliwosci ten static_cast jest za ciezki/
the declaration of ifstream infile; creates a variable called "infile" (an object of input_file_stream class )...this is what you use to do file operations.
because you are trying to open 2 different files you may want to create 2 variables one for each file. unless you are going to process one, then close it, then process the other file.
EDIT: instead of changing the above you can just change:
ifstream infile;
ofstream outfile;
to
ifstream plikwe;
ofstream plikwy;
you should also test to make sure the file opened correctly. eg.
#include <cstdlib>
using std::exit;
// so we can exit program on conditions
int main ()
{
const string delims("\t,.; ");
string line;
ifstream plikwe;
ofstream plikwy;
plikwe.open("plikwe.txt");
plikwy.open("plikwy.txt");// you said they were called, plikwe and plikwy yet your
// trying to open we.txt /wy.txt this will fail, unless you change the filenames.
if (! plikwe.is_open())
{
cout << "ERROR: unable to open input file";
exit (1);
}
elseif (! plikwy.is_open())
{
cout << "ERROR: unable to open output file";
exit (1);
}
// rest of code goes here...
If you want to reverse the characters in a single word, there is an STL algorithm that can do it for you.
For example:
1 2 3 4 5
#include <algorithm>
// ...
string s = "asdf";
reverse( s.begin(), s.end() );
// s now contains "fdsa"
I think the reverseWord function posted above has a few issues. For one, the memory allocated by new is not being deleted. Additionally, wordArray is not null terminated, so returnString may not be constructed properly unless the length is also passed in.