我遇到了一些声明字符串变量的问题。代码和错误在这里:http://pastebin.com/TEQCxpZd。你对我做错了什么有什么想法吗?另外,请保持平台无关性。谢谢!
#include <stdio.h>
#include <string>
using namespace std;
int main()
{
string input; //Declare variable holding a string
input = scanf; //Get input and assign it to variable
printf(input); //Print text
return 0;
}
Getting this from GCC:
main.cpp: In function ‘int main()’:
main.cpp:53:10: error: invalid conversion from ‘int (*)(const char*, ...)’ to ‘char’
main.cpp:53:10: error: initializing argument 1 of ‘std::basic_string<_CharT, _Traits, _Alloc>& std::basic_string<_CharT, _Traits, _Alloc>::operator=(_CharT) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>, std::basic_string<_CharT, _Traits, _Alloc> = std::basic_string<char>]’
main.cpp:54:14: error: cannot convert ‘std::string’ to ‘const char*’ for argument ‘1’ to ‘int printf(const char*, ...)’
()
的情况下调用函数。 - dan04