当我使用just编译程序时
gcc code.c
Run Code Online (Sandbox Code Playgroud)
没有消息,并且成功生成了输出文件.输出的文件有效.但是,当我尝试在IDE中使用相同的cygwin安装的gcc编译器时(我尝试过Netbeans和Dev-C++),我收到以下错误
main.cpp:27: error: `exit' undeclared (first use this function)
main.cpp:27: error: (Each undeclared identifier is reported only once for each function it appears in.)
main.cpp:77: error: `write' undeclared (first use this function)
main.cpp:78: error: `close' undeclared (first use this function)
Run Code Online (Sandbox Code Playgroud)
我看不出有什么不同.为什么不编译?
好的,问题是在IDE中,文件的扩展名为.cpp,而当我从终端编译时,它的扩展名为.c.所以,我的新问题是为什么它被视为c ++文件时不能编译.C不是C++的子集吗?
我在Windows XP上使用Dev C++
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main ()
{
string STRING;
ifstream infile;
infile.open ("sample.txt");
while(!infile.eof)
{
getline(infile,STRING);
cout<<STRING;
}
infile.close();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
此代码给出以下错误
C:\C++\read.cpp: In function `int main()':
C:\C++\read.cpp:11: error: could not convert `infile.std::basic_ios<_CharT, _Traits>::eof [with _CharT = char, _Traits = std::char_traits<char>]' to `bool'
C:\C++\read.cpp:11: error: in argument to unary !
Run Code Online (Sandbox Code Playgroud)
我不知道这里有什么问题我无法编译代码请帮忙
嘿伙计们,我正在为我的工作做一个项目,但我似乎无法弄清楚这一点.
我需要接受制造模型和特定产品适合的汽车年限.该程序将编写一个包含文本的文件,该文件将成为我需要的html大纲,并将关键信息插入正确的位置,以便快速将产品添加到我们的网页中.当我使用switch语句或if语句来分隔产品的类别时,输入会搞砸,并且不允许我回答其中一个问题.我不能只使用cin,因为我需要采取看起来像"2008 - 2009 - 2010 - 2011"的日期
这是我迄今为止所拥有的!这个是常规的cin,我试过getline你可以很快我昨天开始我很新,所以原谅我,如果这是一个简单的解决方案,但我找不到任何东西.
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
void proinfo();
int main()
{
//Sytem Information
system("TITLE This is a Beta of My Product Information Template Version 0.0.2");
//I'm using this as a welcome screen to inform users of new improvements on patches and other pertinent information to the users
cout << "Welcome To My Product Information Template Maker!!! \n It Is Still In Development" << endl; …Run Code Online (Sandbox Code Playgroud) 本周的家庭作业分配是创建一个基本的c ++程序,要求用户输入以英尺和英寸为单位的长度,然后以厘米为单位输出; 我们要创建一个异常并让它处理它,如果用户输入一个负数或一个字符.我有代码写,但当它编译时,我得到错误:
在函数'int main()'中:在第19行的"int"之前的"int"期望')之前的期望的primary-expression.
这是我的代码:
#include <iostream>
using namespace std;
const double centimetersPerInch = 2.54; //named constant
const int inchesPerFoot = 12; //named constant
int main ()
{
int feet;
int inches; //declared variables
int totalInches;
double centimeters;
//statements
cout << "Enter two integers one for feet and " << "one for inches: ";
cin >> feet >> inches;
try
{
if ( int feet, int inches < 0.0 )
throw "Please provide a positive number";
cout << endl; …Run Code Online (Sandbox Code Playgroud) 尝试编译以下代码:
#include <iostream>
#include <memory>
struct Foo {
Foo() { std::cout << "Foo::Foo\n"; }
~Foo() { std::cout << "Foo::~Foo\n"; }
void bar() { std::cout << "Foo::bar\n"; }
};
void f(const Foo &foo)
{
std::cout << "f(const Foo&)\n";
}
int main()
{
std::unique_ptr<Foo> p1(new Foo); // p1 owns Foo
if (p1) p1->bar();
{
std::unique_ptr<Foo> p2(std::move(p1)); // now p2 owns Foo
f(*p2);
p1 = std::move(p2); // ownership returns to p1
std::cout << "destroying p2...\n";
}
if (p1) p1->bar();
// Foo instance is …Run Code Online (Sandbox Code Playgroud) 我正在编写一个 C 程序并使用 Dev C++ 来编译/运行它。
但是,它提出了错误:
undefined reference to 'WinMain'" and "[Error] Id returned 1 exit status"
Run Code Online (Sandbox Code Playgroud)
这些错误是什么意思,我该如何解决?
该WinMain错误似乎与我的代码的第 18 行有关,它是...
int read_char() { return getchar(); }
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?我是 C 的初学者,我还没有找到我理解的这个问题的答案。
我想这是因为我使用的是 Windows。代码可以在 linux 上正常工作吗?
#include <stdio.h>
#include <stdlib.h>
#define f(x) (1 / (x*x+1))
int main(){
double a,b,h,x,y;
printf("Enter a, b, h: ");
scanf(" %lf %lf %lf " , &a, &b, &h);
// I ask for 3 inputs but the programm needs 4 to run...why is that?
x = a;
while(x<b)
{
y = f(x);
printf("%lf %lf \n", x ,y );
x +=h;
}
system("Pause");
return(0);
}
Run Code Online (Sandbox Code Playgroud) 我使用 switch case 语句编写了一个程序并要求输入一个字符,但它没有要求在控制台窗口中输入字符而是完全跳过它
int main()
{
float a, b, ans;
char opr;
printf("\nGIVE THE VALUES OF THE TWO NUMBERS\n");
scanf(" %f %f",&a,&b);
printf("\nGIVE THE REQUIRED OPERATOR\n");
//no display(echo) on the screen
//opr = getch();
//displays on the screen
//opr = getche();
scanf("%c",&opr);
switch(opr)
{
case '+' :
ans = a+b;
printf("%f", ans);
break;
case '-' :
ans = a-b;
printf("%f", ans);
break;
case '*' :
ans = a*b;
printf("%f", ans);
break;
case '/' :
ans = a/b;
printf("%f", ans); …Run Code Online (Sandbox Code Playgroud) 我已经用dev c ++编写了此代码,并且可以工作,但是当我尝试在Visual Studio中运行它时,会出现错误,例如expression必须具有恒定值。
#include <iostream>
using namespace std;
int main() {
int r, c, j;
int matrix[r][c];
cout << "Enter the size of matrix: ";
cin >> j;
for (r = 0; r < j; r++) {
for (c = 0; c < j; c++) {
cout << "matrix" << "[" << r << "]" << "[" << c << "] = ";
cin >> matrix[r][c];
}
}
cout << "\n";
for (int i = 0; i …Run Code Online (Sandbox Code Playgroud) 90% 的应用程序显示正确清晰,就像我的超高清笔记本电脑屏幕上应有的那样。我的缩放比例是 150%(也是默认值)(由于 15.6 英寸笔记本电脑的超高清屏幕,100% 对我的眼睛来说效率太低。)
但 dev c++ 和一些旧软件看起来很模糊。
Windows 10 设置中有一个名为“高级缩放”的修复程序已启用。有什么方法可以修复模糊的 dev c++ 或者您是否推荐更好的带有编译器的最新 ide for c++?
(带有 mingw 的 eclipse-cpp 很慢,clion 很棒,但使用 Visual C++ 编译器(我不知道编译器是否有任何设置,Microsoft Visual C++ 很好,但没有显示一些错误,实际上说“没有错误”而不是编译)有一段时间)
dev-c++ ×10
c++ ×7
c ×3
arrays ×1
c++11 ×1
char ×1
compilation ×1
eof ×1
fstream ×1
gcc ×1
ide ×1
scaling ×1
scanf ×1
unique-ptr ×1
visual-c++ ×1
windows-10 ×1