所以这是我的代码,在查找预编译的头文件时,我不断收到“意外的文件结尾。”你是否忘记将#include stdafx.h添加到你的源代码?所以我把它添加到所有标题和文件,它仍然说同样的错误。我如何摆脱错误?
P.S。如果你不介意检查这段代码是否回答了这些问题(乘法和除法重载我几乎没有开始,但关系和平等应该没问题)
Hugeint.h
#ifndef HUGEINT_H
#define HUGEINT_H
#include <array>
#include <iostream>
#include <string>
#include "stdafx.h";
class Hugeint
{
friend std::ostream &operator<<(std::ostream &, const Hugeint &);
public:
static const int digits = 30;
Hugeint(long = 0);
Hugeint(const std::string &);
Hugeint operator+(const Hugeint &) const;
Hugeint operator+(int) const;
Hugeint operator+(const std::string &) const;
Hugeint operator*(const Hugeint &) const;
Hugeint operator/(const Hugeint &) const;
//relation
bool operator<(const Hugeint &) const;
bool operator<=(const Hugeint &) const;
bool operator>(const Hugeint &) const;
bool operator>=(const Hugeint &) const;
//equal
bool operator==(const Hugeint &) const;
bool operator!=(const Hugeint &) const;
private:
std::array< short, digits > integer;
//short arrayInt[ max ];
};
#endif
Hugeint.cpp
#include <cctype>
#include "HugeInt.h"
#include "stdafx.h"
using namespace std;
Hugeint::Hugeint(long value)
{
for (int i = 0; i<digits; i++)
integer[i] = 0;
for (size_t j = digits - 1; value != 0 && j >= 0; --j)
{
integer[j] = value % 10;
value /= 10;
}
}
Hugeint::Hugeint(const string &number)
{
for (int i = 0; i<digits; i++)
integer[i] = 0;
size_t length = number.size();
for (size_t j = digits - length, k = 0; j < digits; ++j, ++k)
if (isdigit(number[k]))
integer[j] = number[k] - '0';
}
Hugeint Hugeint::operator+(const Hugeint &op2) const
{
Hugeint temp;
int carry = 0;
for (int i = digits - 1; i >= 0; --i)
{
temp.integer[i] = integer[i] + op2.integer[i] + carry;
if (temp.integer[i] > 9)
{
temp.integer[i] %= 10;
carry = 1;
}
else
carry = 0;
}
return temp;
}
Hugeint Hugeint::operator+(int op2) const
{
return *this + Hugeint(op2);
}
Hugeint Hugeint::operator+(const string &op2) const
{
return *this + Hugeint(op2);
}
bool Hugeint::operator<(const Hugeint &hugeInt) const
{
bool less = false;
for (int i = digits - 1; i >= 0 && !less; --i)
{
if (integer[i] <hugeInt.integer[i])
{
less = true;
}
}
return less;
}
bool Hugeint::operator<=(const Hugeint &hugeInt) const
{
bool LessThan = false;
for (int i = digits - 1; i >= 0 && !LessThan; --i)
{
if (integer[i] <= hugeInt.integer[i])
{
LessThan = true;
}
}
return LessThan;
}
bool Hugeint::operator>(const Hugeint &hugeInt) const
{
bool greater = false;
for (int i = digits - 1; i >= 0 && !greater; --i)
{
if (integer[i] >hugeInt.integer[i])
{
greater = true;
}
}
return greater;
}
bool Hugeint::operator>=(const Hugeint &hugeInt) const
{
bool GreaterThan = false;
for (int i = digits - 1; i >= 0 && !GreaterThan; --i)
{
if (integer[i] >= hugeInt.integer[i])
{
GreaterThan = true;
}
}
return GreaterThan;
}
bool Hugeint::operator==(const Hugeint &hugeInt) const
{
bool eqaul = true;
for (int i = digits - 1; i >= 0 && eqaul; --i)
{
if (integer[i] != hugeInt.integer[i])
{
eqaul = false;
}
}
return eqaul;
}
ostream& operator<<(ostream &output, const Hugeint &num)
{
size_t i;
for (i = 0; (i < Hugeint::digits) && (0 == num.integer[i]); ++i);
if (i == Hugeint::digits)
output << 0;
else
for (; i < Hugeint::digits; ++i)
output << num.integer[i];
return output;
}
的main.cpp
#include<iostream>
#include<string>
#include "Hugeint.h"
#include "stdafx.h"
using namespace std;
int main(){
char value1[30];
char value2[30];
cout << "enter HugeInt1 : ";
cin >> value1;
Hugeint hugeInt1(value1);
cout << "enter HugeInt2 : ";
cin >> value2;
Hugeint hugeInt2(value2);
cout << "< opertor " << endl;
if (hugeInt1 < hugeInt2) {
cout << hugeInt1 << " is less than " << hugeInt2 << endl;
}
else {
cout << hugeInt1 << " is not less than " << hugeInt2 << endl;
}
cout << "<= opertor " << endl;
if (hugeInt1 <= hugeInt2) {
cout << hugeInt1 << " is less than or eqaul " << hugeInt2 << endl;
}
else {
cout << hugeInt1 << " is not less than or equal " << hugeInt2 << endl;
}
cout << "> opertor " << endl;
if (hugeInt1 > hugeInt2) {
cout << hugeInt1 << " is greater than " << hugeInt2 << endl;
}
else {
cout << hugeInt1 << " is not greater than " << hugeInt2 << endl;
}
cout << ">= opertor " << endl;
if (hugeInt1 >= hugeInt2) {
cout << hugeInt1 << " is greater than or eqaul " << hugeInt2 << endl;
}
else {
cout << hugeInt1 << " is not greater than or equal " << hugeInt2 <<
endl;
}
cout << "== opertor " << endl;
if (hugeInt1 == hugeInt2) {
cout << hugeInt1 << " is eqaul to " << hugeInt2 << endl;
}
else {
cout << hugeInt1 << " is not equal to " << hugeInt2 << endl;
}
system("pause");
return 0;
}
答案 0 :(得分:3)
gcloud compute ssh my_username@instance-1 \
--command="cd project_folder && python my_script.py && sudo shutdown now"
必须是第一个包含在配置为使用预编译标头的每个源文件中(删除无关的#include "stdafx.h"
个字符方式)。这些文件必须具有;
编译标志。
还必须有一个创建预编译头的源文件。传统上,这称为-Yu
,仅包含单行stdafx.cpp
。该文件必须具有#include "stdafx.h"
编译标志。
答案 1 :(得分:1)
In Visual Studio you could create C++ project -> EmptyProject and than just add main.cpp file with int main() {}
function. In that case all be work fine, and no precompiled headers needed.