简体   繁体   English

针对此cpp代码使用cl.exe(Visual Studio 2008)编译错误

[英]Compile error using cl.exe (Visual Studio 2008) for this cpp code

I'm getting compile error in this code 我在此代码中出现编译错误

    #include<iostream>
    #include<cstdio>
    #include<string>
    using namespace std;
    void main(int argc,char *argv[])
    {
        int i;
        for(i = 0;i<10;i++)
           fprintf(cout,"%d\n",i);
        fprintf(cout,"abc:\n");
        string s;
        cin>>s;
        if(s == "resume") { 
            for(i = 0;i<10;i++)
            fprintf(cout,"%d\n",i);
        }
   }

Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.21022.08 for 80x86 Copyright (C) Microsoft Corporation. 用于80x86的Microsoft(R)32位C / C ++优化编译器版本15.00.21022.08版权所有(C)Microsoft Corporation。 All rights reserved. 版权所有。

try.cpp C:\\Program Files\\Microsoft Visual Studio 9.0\\VC\\INCLUDE\\xlocale(342) : warning C 4530: C++ exception handler used, but unwind semantics are not enabled. try.cpp C:\\ Program Files \\ Microsoft Visual Studio 9.0 \\ VC \\ INCLUDE \\ xlocale(342):警告C 4530:使用了C ++异常处理程序,但未启用展开语义。 Specify /EHsc 指定/ EHsc

try.cpp(9) : error C2664: 'fprintf' : cannot convert parameter 1 from 'std::ostr eam' to 'FILE *' No user-defined-conversion operator available that can perform this conv ersion, or the operator cannot be called try.cpp(9):错误C2664:'fprintf':无法将参数1从'std :: ostr eam'转换为'FILE *'没有可用的用户定义转换运算符可以执行此转换,或者该运算符不能叫做

try.cpp(10) : error C2664: 'fprintf' : cannot convert parameter 1 from 'std::ost ream' to 'FILE *' No user-defined-conversion operator available that can perform this conv ersion, or the operator cannot be called try.cpp(10):错误C2664:'fprintf':无法将参数1从'std :: ost ream'转换为'FILE *'没有可用的用户定义转换运算符可以执行此转换,或者该运算符无法叫做

try.cpp(16) : error C2664: 'fprintf' : cannot convert parameter 1 from 'std::ost ream' to 'FILE *' No user-defined-conversion operator available that can perform this conv ersion, or the operator cannot be called try.cpp(16):错误C2664:'fprintf':无法将参数1从'std :: ost ream'转换为'FILE *'没有可用的用户定义转换运算符可以执行此转换,或者该运算符无法叫做

what is wrong? 怎么了?

You are mixing up C++ and C output styles. 您正在混合使用C ++和C输出样式。 Change your fprintfs to look like: 将fprintfs更改为以下形式:

cout << "value is: " << i << "\n";
std::fprintf(stdout, )

std :: cout没有FILE *类型。

Alternately, change your includes to: 或者,将您的包含更改为:

#include <stdio.h>
#include <string.h>

and the fprintf() calls to fprintf()调用

fprintf(stdout,"abc:\n");

Then you're talking C . 那你在说C

You are mixin C and C++ incorrectly. 您混入C和C ++错误。 Use only 1, and stick to it untill you learn what the difference between the types are. 仅使用1,并坚持下去,直到您了解类型之间的区别。

Here's your code without compilation errors: 这是没有编译错误的代码:

#include <iostream>
#include <string>

int main()
{
  using namespace std;

  for(int i = 0; i < 10; i++)
    cout << i << '\n';
  cout << "abc" << endl;

  string s;
  cin >> s;
  if(s == "resume") 
    for(int i = 0; i < 10; i++)
      cout << i << '\n';

  return 0;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM