在visualstudio中创建c++代码并在g++中运行
Creating c++ code in visual studio and running it in g++
我已经在visualstudio中创建了c++代码,但大学的规范是它需要在g++编译器中运行。
该代码在visualstudio中运行良好,但在g++中根本不起作用。为什么会这样?有没有一种简单的方法可以让代码在g++中工作?
这是我的密码。
#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");
}
尽管据我所知,linux系统上没有system("pause")
,但我认为交叉编译没有问题。
错误缺少终止字符。这是由于第二个t
缺少引号
这个
file << n <<"t" << setw(14) << G.at(n)<<"t<<setprecision(15)<<R.at(n)<<endl;
应该是这个吗
file << n <<"t" << setw(14) << G.at(n)<<"t"<<setprecision(15)<<R.at(n)<<endl;
要使用system()
函数,必须将#include <stdlib.h>
添加到项目中并更改
file << n <<"t" << setw(14) << G.at(n)<<"t<<setprecision(15)<<R.at(n)<<endl;
至
file << n <<"t" << setw(14) << G.at(n)<<"t"<<setprecision(15)<<R.at(n)<<endl;
然后用g++编译100%。
相关文章:
- 运行同一解决方案的另一个项目的项目
- CMake-按正确顺序将项目与C运行时对象文件链接
- 如何运行位于boost/libs/python/example/tutorial目录中的hello.cpp和Jamfil
- 代码在main()中运行,但在函数中出现错误
- 我在c++代码中生成了一个运行时#3异常
- 如何在linux终端中同时编译和运行c++代码
- 为什么在运行时没有向我们提供有关分段错误的更多信息?
- 如何在运行中期切换GTK CSS style_context
- 如何在MS Visual Studio 2019中运行QT UI
- 如何通过cpp程序运行shell脚本
- IPC使用多个管道和分支进程来运行Python程序
- 删除指向指针的指针是运行时错误吗
- 如何用参数值调用函数(仅在运行时已知)
- 为什么即使使用-cudart-static进行编译,库用户仍然需要链接到cuda运行时
- 是否可以在编译时初始化数组,以便在运行时不会花费时间?
- c++中的指针和运行时错误
- 在C应用程序中运行C++(带有STL)函数
- 运行程序时出现问题
- 控制允许动态运行c++的并发操作数
- 无法获取菜单选择以运行函数.C++