为什么我的C++程序不起作用?
Why isn't my C++ program working?
不知道为什么这不起作用,一切似乎都是对的,但也许我在了解C++的过程中错过了一些显而易见的东西。
程序:
#include <iostream>
#include <string>
using namespace std;
string ask(){
string ans2;
cout << "Type:";
cin >> ans2;
return ans2;
}
int main()
{
string ans2;
string ans1="Hello";
ask();
cout << ans1 << " turns into " << ans2;
return 0;
}
错误信息为:
Line 20:[Error] no match for call to '(std::string {aka std::basic_string<char>}) (std::string&)'
Line 6:[Error] 'ans2' was not declared in this scope
Line 6:[Error] expected ',' or ';' before '{' token
main
和ask
中的ans2
是两个不同的变量。当您在ask
函数中返回ans2
的值时,您需要通过ans2 = ask();
在main
函数中捕获它。Videone 的工作示例
相关文章:
- 在C++程序中输入的文本文件将不起作用,除非文本被复制和粘贴
- sigwait() 在多线程程序中不起作用
- 为什么使用数组元素查找最大数字的程序不起作用?
- C++实用程序::转换在静态链接库中不起作用
- Cuda 基本程序 (将值写入矩阵和 std:cout 不起作用) ;主功能不启动
- 视窗 10 :笔(手写笔)在 MFC 应用程序上不起作用
- win32 滚动条在 C/C++ 程序中不起作用
- 用于拆分空格字符串的程序不起作用
- 反转一个数字程序不起作用,为什么?
- C++ 程序在代码块 IDE 中不起作用
- 该程序将.csv文件中的一系列单词放入数组中,然后随机生成句子.但它不起作用
- 程序在CLion IDE中工作,但exe不起作用
- Opencv在2013年第5季度不起作用.应用程序总是在窗口中崩溃
- C++从句子中删除给定字符的程序不起作用
- C ++ GCC 内联程序集似乎不起作用
- 为什么当我选择>250000个采样点时,程序不起作用?
- 任务计划程序库的预处理不起作用 - 多定义错误
- C 为什么我的程序循环和"if-statements"不起作用?
- try() 和 catch() 不起作用;程序崩溃,从不执行 catch() 块
- Cin 执行不起作用 (程序.exe <文件与数据.txt)