gpt4 book ai didi

不能使用 MS Visual C++ 在 C 中包含 iostream?

转载 作者:太空宇宙 更新时间:2023-11-04 06:06:13 24 4
gpt4 key购买 nike

我一直在尝试学习 C,但一直坚持包含库。我需要使用 strcpy(),但该方法包含在 iostream 库中,但每当我尝试包含该库时,程序都会给我错误。我试过使用“iostream”、“iostream.h”、、、,但它要么给我一个“找不到 iostream.h”错误,要么程序超过 100 个错误而崩溃。即使我的代码是空的,我仍然得到同样的结果。这是代码:

#include "iostream"

int main(void)
{
}

是的,就那么多就已经崩溃了。这是我遇到的部分错误(永远无法将它们全部粘贴到此处):

1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(37): error C2061: syntax error : identifier 'abs'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(37): error C2059: syntax error : ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(39): error C2061: syntax error : identifier 'acos'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(39): error C2059: syntax error : ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(39): error C2061: syntax error : identifier 'asin'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(39): error C2059: syntax error : ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(40): error C2061: syntax error : identifier 'atan'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(40): error C2059: syntax error : ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(40): error C2061: syntax error : identifier 'atan2'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(40): error C2059: syntax error : ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(40): error C2061: syntax error : identifier 'ceil'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(40): error C2059: syntax error : ';'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(41): error C2061: syntax error : identifier 'cos'
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\cmath(41): fatal error C1003: error count exceeds 100; stopping compilation
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

是的,它甚至超过了 100 个错误,程序就停止计数了。我不明白为什么,我只是包括一个普通图书馆。是否有 strcpy() 的等价物?我主要想像这样使用它(练习):

#include "stdafx.h"
#include "stdlib.h"
#include "stdio.h"
#include "conio.h"
#include "iostream"

int main(void)
{
struct person
{
int id;
char name[50];
int age;
};

struct person p1;

p1.id = 5595;
strcpy(p1.name, "Myname");
p1.age = 18;

printf("%d%s%d", p1.id, p1.name, p1.age);
}

最佳答案

<iostream>是一个 C++ 头文件(顾名思义,它处理输入/输出流)。如果你想要strcpy , 你需要 <string.h> .

关于不能使用 MS Visual C++ 在 C 中包含 iostream?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10058273/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com