[英]Creating c++ code in visual studio and running it in g++
I have created c++ code in visual studio but the university specification is that it needs to run in g++ compiler.我在 Visual Studio 中创建了 c++ 代码,但大学规范是它需要在 g++ 编译器中运行。
The code works perfectly in visual studio but does not work at all in g++.代码在 Visual Studio 中完美运行,但在 g++ 中根本不起作用。 Why is this?
为什么是这样? Is there an easy way to make the code work in g++?
有没有一种简单的方法可以让代码在 g++ 中工作?
This is the code I have.这是我的代码。
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <fstream>
using namespace std;
int main ()
{
vector<long double> G;
vector<long double> R;
int n=1;
long double result =1;
R.assign(2,0);
G.assign(2,123);
G.at(1)=321;
while (result >= 0.0000000000000001)
{
n++;
G.push_back((G.at(n-2) - G.at(n-1)));
R.push_back(G.at(n)/G.at(n-1));
result = abs(R.at(n) - R.at(n-1));
ofstream file;
file.open("series.txt", std ::ios_base ::app);
file << n <<"\t" << setw(14) << G.at(n)<<"\t<<setprecision(15)<<R.at(n)<<endl;
//cout << n <<"\t" <<setw(14)<<G.at(n)<<"\t"<<setprecision(15)<<R.at(n)<<endl;
file.close();
}
system("pause");
}
There is no issue with cross compiling in my opinion, although to the best of my knowledge there is no system("pause")
on linux systems.在我看来,交叉编译没有问题,尽管据我所知,Linux 系统上没有
system("pause")
。
The error is missing terminating character.错误缺少终止字符。 Which is due to miss quotation marks at the second
\\t
这是由于在第二个
\\t
处遗漏了引号
This这个
file << n <<"\t" << setw(14) << G.at(n)<<"\t<<setprecision(15)<<R.at(n)<<endl;
should be this应该是这个
file << n <<"\t" << setw(14) << G.at(n)<<"\t"<<setprecision(15)<<R.at(n)<<endl;
for use of system()
function you must add #include <stdlib.h>
to your project and change要使用
system()
函数,您必须将#include <stdlib.h>
添加到您的项目并更改
file << n <<"\t" << setw(14) << G.at(n)<<"\t<<setprecision(15)<<R.at(n)<<endl;
to到
file << n <<"\t" << setw(14) << G.at(n)<<"\t"<<setprecision(15)<<R.at(n)<<endl;
then it compile 100 percentage with g++.然后它用 g++ 编译 100%。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.