Mik*_*ike 7 c++ string variables declaration
我在声明字符串变量时遇到了一些麻烦.代码和错误在这里: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*, ...)’
Run Code Online (Sandbox Code Playgroud)
您正在混合使用c ++和c I/O. 在C++中,这是,
#include <string>
#include <iostream>
int main(void)
{
std::string input;
std::cin >> input;
std::cout << input;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
53905 次 |
最近记录: |