我刚刚开始使用c ++
这里是基本主要声明的代码,基于我发现的许多tutorails,还包含打印hello world到控制台的代码
// TestApp.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
std::cout << "Hello World";
}
Run Code Online (Sandbox Code Playgroud)
我正在使用VS 2012 Express,我不知道哪个编译器,但"cout"用红色加下划线
错误如下:
错误C2039'cout':是'std'的成员9 col 1错误C2065:未声明的标识符ln 9 col 1 IntelliSense:名称空间"std"没有成员"cout"ln 9 col 7
我不明白为什么会出错,有人可以赐教吗?
我正在使用此代码...
#include <stdio.h>
int main(int argc,char *argv[]){
int i =0;
if (argc == 1){
printf("You have entered 1 argument and you suck \n");
}
else if (argc > 1 && argc<4){
for (i=0;i<4;i++){
printf("you have entered the following args %d.%s \n",(i),argv[i]);
}
printf("\n");
}
else{
printf("You have entered more than four arguments and you suck.\n");
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
如果我改变从环for (i=0;i<4;i++)到for (i=0;i<7;i++),我得到如下的输出:
cam@cam:~/Desktop/D/c/c-code$ ./ex12 hi there
you have entered the following args 0../ex12
you have entered …Run Code Online (Sandbox Code Playgroud) public class test1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Thread t = Thread.currentThread();
System.out.println(t);
}
}
Run Code Online (Sandbox Code Playgroud)
为什么上面代码的输出是 - Thread[main,5,main] ?请解释
有没有一种简单的方法可以main()在 C++ 中的 Visual Studio 2019 中进行单元测试?
我已经尝试#including了 main.h 并main()从测试中调用,但它“看起来”像是在main()调用测试,从而导致递归。
我想很早就向学生介绍测试(编写代码使测试变得绿色),学生将(还)没有函数或类的经验。
仅供参考,我们正在使用 GoogleTest,但可以更改该选择。
c++ unit-testing program-entry-point googletest visual-studio
所以我从别处看到了一个程序,声明在主函数之外。就像这段代码:
#include<iostream>
using namespace std;
int num1, num2;
int *ptr1 = &num1, *ptr2 = &num2;
char operation, answer;
char *ptrop = &operation;
int main(){
}
Run Code Online (Sandbox Code Playgroud)
但是我现在使用的是在 main 函数中,如下所示:
#include<iostream>
using namespace std;
int main(){
int num1, num2;
int *ptr1 = &num1, *ptr2 = &num2;
char operation, answer;
char *ptrop = &operation;
Run Code Online (Sandbox Code Playgroud)
那么与它有什么区别呢?
我目前正在做计算机科学的 CS50 介绍:我开始编写这段代码(用 C 编写),我必须根据用户编写的内容编写金字塔。
这是我的代码:
#include <stdio.h>
#include <cs50.h>
int main(void);
int n;
do
{
n = get_int("Positive Number: \n");
}
while (n > 0 || n < 9);
Run Code Online (Sandbox Code Playgroud)
这是我的终端显示的错误:
Run Code Online (Sandbox Code Playgroud)mario.c:6:1: error: expected identifier or '(' do ^ mario.c:10:1: error: expected identifier or '(' while (n > 0 || n < 9); ^ 2 errors generated. <builtin>: recipe for target 'mario' failed make: *** [mario] Error 1
有人可以帮忙吗?威廉
请注意,这个问题在这里已经有类似的答案,我想指出:
然而,这个问题更多地询问它们的返回格式以及它们如何相互关联(我认为上面的问题没有完全涵盖)。
_start和之间有什么区别main?在我看来,像ld用途_start,但gcc用途main为切入点。我注意到的另一个区别是main似乎返回值 in %rax,而_start返回值 in%rbx
以下是我看到的两种方式的示例:
.globl _start
_start:
mov $1, %rax
mov $2, %rbx
int $0x80
Run Code Online (Sandbox Code Playgroud)
并运行它:
$ as script.s -o script.o; ld script.o -o script; ./script; echo $?
# 2
Run Code Online (Sandbox Code Playgroud)
另一种方式:
.globl main
main:
mov $3, %rax
ret
Run Code Online (Sandbox Code Playgroud)
并运行它:
$ gcc script.s -o script; ./script; echo $?
3
Run Code Online (Sandbox Code Playgroud)
这两种方法有什么区别?是否main自动调用_start某处,或者它们如何相互关联?为什么一个返回它们的值,rbx而另一个返回它的值rax …
main()C 中的函数有多个定义。
int main (void) { body } (1)
int main (int argc, char *argv[]) { body } (2)
Run Code Online (Sandbox Code Playgroud)
(https://en.cppreference.com/w/c/language/main_function)。
这怎么可能,因为 C 不能有同一个函数的多个声明/定义?
我的学校总是教用void main()C 和 C++ 编写。这是在我高中毕业后,我通过这个社区发现你不会void main()用 C++ 和 C 编写。有谁知道为什么学校这样教我们,因为说实话,现在我习惯了写void main......(印度)
我们一直使用 Turbo C++,它工作得很好,但是当我开始使用 Visual C++ 时,我开始了解这一点。
这个java代码应该可以工作,但它会出错:
no main classes found.
Run Code Online (Sandbox Code Playgroud)
我知道没有专门的"公共静态无效主"课程,但我不需要一个,对吗?我正在使用NetBeans IDE.
public enum Face
{
TWO(2),
THREE(3),
FOUR(4),
FIVE(5),
SIX(6),
SEVEN(7),
EIGHT(8),
NINE(9),
TEN(10),
JACK(11),
QUEEN(12),
KING(13),
ACE(14);
private int cardValue;
private Face (int value)
{
this.cardValue = value;
}
public int getCardValue() {
return cardValue;
}
}
public enum Suit
{
HEARTS,
SPADES,
CLUBS,
DIAMONDS;
}
public class Card
{
private Suit suit;
private Face cardValue;
public Card (Face cardValue, Suit suit)
{
this.cardValue = cardValue;
this.suit = suit;
}
public Suit getSuit() …Run Code Online (Sandbox Code Playgroud)