Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
This post was edited and submitted for review last year and failed to reopen the post:
Original close reason(s) were not resolved
Improve this question
I am a newbie and a student of Computer Sciences. I am doing my assignment Which is spell checker of a text file. I have done the code but I am getting the following errors. I am unable to resolve it. kindly help me guys. Thanks!
Here is my code:
#include<iostream>
#include<fstream>
using namespace std;
class spell_check
{
private:
int line_number=0;
string input="" ;
string dictionary="";
bool condition=false;
public:
void process(int x,char *y[]);
};
void spell_check::process(int x,char *y[])
{
ifstream input_file;
input_file.open(y[2]);
ofstream output_file;
output_file.open(y[4]);
while(!input_file.eof())
{
line_number++;
getline(input_file,input);
ifstream dictionary_file("dictionary.txt");
while(!dictionary_file.eof())
{
getline(dictionary_file,dictionary);
if( input.compare(dictionary) == 0 )
{
condition=true;
break;
}
}
if(condition==false)
{
output_file<<"**Spell mistake** "<< "( " << input << ")"<< "[" <<"at line no: " << line_number <<"]"<<endl;
}
dictionary_file.close();
condition=false;
}
cout<<"Successfully Write "<<endl;
input_file.close();
output_file.close();
}
int main(int argum,char *argu_array[])
{
spell_check SC;
SC.process(argum, *argu_array);
return 0;
}
there is an error here:
int main(int argum,char *argu_array[])
{
spell_check SC;
SC.process(argum, *argu_array);
return 0;
}
since the type of the second argument of the main function is char* []
and also the type of the argument of the process method is the same:
void spell_check::process(int x,char *y[])
you don't have to dereference it, try this:
SC.process(argum, argu_array);
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 days ago.
Improve this question
I get this error when I try to compile the following code: Exception thrown: write access violation.
this was 0xF81EFA0000.
#include <iostream>
using namespace std;
class Demo
{
int x;
public:
void setX(int i)
{
x = i;
}
int getX()
{
return x;
}
};
int main() {
Demo obj[4];
int i;
for (i = 0; 1 < 4; i++)
{
obj[i].setX(i);
}
for (i = 0; i < 4; i++)
{
cout << "obj[" << i << "].getX(): " <<
obj[i].getX() << endl;
}
// Textual Data Types
// Boolean
return 0;
}
The error concerns line 10, where "x = i" is written. Any help would be good.
I haven't tried anything to fix it, other than writing brackets after "x", which obviously didn't work. I expect this program to print an array of objects when working properly.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 6 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
i am attending a online competition. my code is working in my compilier visual studio 2013. but the online judges giving me compilation error.
here is my code.
#include<iostream>
#include<string>
#include<cmath>
#include<fstream>
using namespace std;
void main() {
int first_number;
int second_number;
string str;
char ch;
int count = 0;
ifstream yfile("q4.txt");
while (!yfile.eof())
{
yfile >>first_number;
if (first_number < 0)
first_number = abs(first_number);
yfile >> ch;
yfile >> second_number;
if (second_number < 0)
second_number = abs(second_number);
int gcd;
for (int i = 1; i <= first_number&&i <= second_number; i++){
if (first_number%i == 0 && second_number%i == 0){
gcd = i;
}
}
cout << "Output: " << gcd << endl;
}
can anyone please tell me solution? I will be thankful to you.
}
The code posted has one missing curly brace at the end.
error: ‘::main’ must return ‘int’
Try using
int main() {
instead. And add a return 0; statement at the end (or whatever return value you want).
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I have looked around and have sen this question asked a fair bit but I the problems they are having seem different to mine.
I am only a beginner so I find it kind of hard to understand whats wrong with my program. Here is the code:
#include <string>
#include <iostream>
using namespace std;
class Character
{
int health;
string action;
public:
void setHealth(int hp) {health = hp;}
void setAction(string act) {action = act;}
int getHealth() {return health;}
string getAction() {return action;}
};
int main()
{
int difficulty;
Character player;
player.setHealth(15);
Character enemy;
cout << "What difficulty would you like to play? easy = 1, medium = 2, hard = 3 ";
cin >> difficulty;
switch (difficulty)
{
case 1 : enemy.setHealth(10); break;
case 2 : enemy.setHealth(15); break;
case 3 : enemy.setHealth(20); break;
}
cout << "\nEnemy health = " << enemy.getHealth << endl;
return 0;
}
And here is the error message I get: In function 'int main()':
36:39: error: invalid use of non-static member function
It appears the problem is at the cout at the bottom of the main function.
Please help!
getHealth() is a class method, not a member, so it should be:
cout << "\nEnemy health = " << enemy.getHealth() << endl;
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
What have I done wrong with the following code?
#include <iostream>
using namespace std;
main ()
{
int a;
int b;
int sum;
cout << "Enter first number \n";
cin >> a;
cout << "Enter second number \n";
cin >> b;
sum = a+b;
cout << "The sum of both numbers is" << sum << endl;
return 0;
}
Does the editor you are using tells errors, so the code is not executing? Or som exception rises? Or it is executing but nothing is shown? Please specify your problem accurately.
Anyway, you must use
int main ()
instead of
main()
Notice that your code returns a value. The last line of you code is:
return 0;
Thus, you must specify an int return type.
Check your initial lines with this.
#include <iostream>
using namespace std;
int main ()
{
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
Following is my code:
I am unable to reverse the string using reverse in file algorithm
#include<iostream>
#include<fstream>
#include<string>
#include<algorithm>
#include<iterator>
using namespace std;
int main()
{
ifstream fp;
string line;
fp.open("list");
if(!fp.is_open())
{
cerr<<"file not open";
}
while(!fp.eof())
{
getline(fp,line);
cout<<line<<end;
std::reverse(line.begin(),line.end());
}
}
Compilation error I get is:
file.cpp: In function ‘int main()’:
file.cpp:21:15: error: ‘end’ was not declared in this scope
As it already was said in comments in statement
cout<<line<<end;
you wrote end instead of endl
However I would like to say about the algorithm reverse. I do not see a sense in your code because each time variable line is being overwritten. So you do not see the effect of the reversing. Maybe it would be better to write
while( getline( fp, line ) )
{
cout << line << endl;
std::reverse_copy( line.begin(), line.end(), ostream_iterator<string>( cout, "\n" ) );
}
Only you need to include header <iterator>
Also you can reverse an object of type std::string without explicitly using algorithm reverse. For example
cout << line << endl;
line.assign( line.rbegin(), line.rend() );
cout << line << endl;
or
cout << line << endl;
cout << string( line.rbegin(), line.rend() ) << endl;
Your string reverse logic is working. The problem is typo :D
cout<<line<<end;
should be
cout<<line<<endl;