具有#include <string>的C ++并获取C2679

时间:2019-12-02 01:48:22

标签: c++

感谢@crashmstr触发右脑细胞正常工作。我的问题是您不能将具有该格式的整数写入数组。
cin >>票[a] [0];是解决问题的正确答案。

#include<iostream>
#include<iomanip>
#include<istream>
#include<string>
using namespace std;
const int nameRow = 6, nameCol = 7, voteRow = 6, voteCol = 2;

int main ( )
{
    char candName[nameRow][nameCol];
    int votes[voteRow][voteCol];
    for(int a=0;a< nameRow;a++)
        for (int b = 0; b < nameCol;b++)        
            candName[a][b] = 0;
    for (int c = 0; c < voteRow;c++)
        for (int d = 0; d < voteCol;d++)
            votes[c][d] = 0;


    cout << "Enter a candidate's name : ";
    for (int a = 0;a < nameRow;a++)
    {
        cin >> candName[a], nameCol;
        cin >> votes[a], voteCol;
    }

    system ( "pause" );
}

我的问题是文件的最后一个cin。 >>正在获取代码。我把它放在同一行,另一个循环,相同功能的不同循环或不同功能的所有行的>>跳闸C2679都没关系。 我看到的最流行的修复方法是使用#include<string.h>,并将其更改为<string>。最初我没有它,但是看到它时就添加了它,但是它并没有解决任何问题。 谁能给我一些我所缺少的见识?

错误消息:

binary '>>' : no operator found which takes a right-hand operand of type 'int[2]' (or there is no acceptable conversion) 

3 个答案:

答案 0 :(得分:1)

使用#include <string>是解决方案的一部分,但是您忘记了实际使用字符串类型。另外,您还会使用很多古董。代码如下:

#include<iostream>
#include<iomanip>
#include<string>

const int numRows = 6;

int main ( )
{
    std::string candName[numRows];      // empty strings
    int votes[numRows] {};              // zero-initialized

    for (int a = 0;a < numRows;a++)
    {
        std::cout << "Enter a candidate's name : ";
        std::cin >> candName[a] >> votes[a];

        if ( ! std::cin )
            break;      // stop if they type something bad
    }
}

另一个容易进行的修改是将结果存储在用户定义类型的vector中,该类型包含stringint,而不是具有两个固定大小的数组。然后,您可以接受任意数量的输入,而不仅仅是6个。

答案 1 :(得分:-2)

这需要解决,将2019-12-02 02:32:47 DEBUG rasa.core.processor - Logged UserUtterance - tracker now has 5 events 2019-12-02 02:32:47 DEBUG rasa.core.policies.memoization - Current tracker state [None, None, None, {}, {'entity_authentication_api_token': 1.0, 'entity_authentication_back_end': 1.0, 'intent_login_all_intents': 1.0, 'slot_endpoint_0': 1.0, 'prev_action_listen': 1.0, 'slot_authentication_back_end_0': 1.0, 'entity_endpoint': 1.0, 'slot_authentication_api_token_0': 1.0}] 2019-12-02 02:32:47 DEBUG rasa.core.policies.memoization - There is a memorised next action '8' 2019-12-02 02:32:48 DEBUG rasa.core.policies.form_policy - There is no active form 2019-12-02 02:32:48 DEBUG rasa.core.policies.ensemble - Predicted next action using policy_0_MemoizationPolicy 2019-12-02 02:32:48 DEBUG rasa.core.processor - Predicted next action 'action_user_login' with confidence 1.00. 2019-12-02 02:32:48 DEBUG rasa.core.actions.action - Calling action endpoint to run action 'action_user_login'. 2019-12-02 02:32:50 DEBUG rasa.core.processor - Action 'action_user_login' ended with events '['BotUttered(text: {\'Authorization\': \'`<auth_code>\'}, data: {"elements": null, "quick_replies": null, "buttons": null, "attachment": null, "image": null, "custom": null}, metadata: {})', "SlotSet(key: authorization, value: {'Authorization': '`<auth_code>'})"]' 2019-12-02 02:32:50 DEBUG rasa.core.processor - Current slot values: authentication_api_token: <api_token> authentication_back_end: beta authorization: {'Authorization': '`<auth_code>'} endpoint: authentication requested_slot: None 2019-12-02 02:32:50 DEBUG rasa.core.lock_store - Deleted lock for conversation 'default'. 2019-12-02 02:32:56 ERROR asyncio - Task exception was never retrieved future: <Task finished coro=<configure_app.<locals>.run_cmdline_io() done, defined at c:\app\miniconda2\envs \my-envs\lib\site-packages\rasa\core\run.py:124> exception=TimeoutError()> Traceback (most recent call last): File "c:\app\miniconda2\envs \my-envs\lib\site-packages\rasa\core\run.py", line 128, in run_cmdline_io server_url=constants.DEFAULT_SERVER_FORMAT.format("http", port) File "c:\app\miniconda2\envs \my-envs\lib\site-packages\rasa\core\channels\console.py", line 135, in record_messages async for response in bot_responses: File "c:\app\miniconda2\envs \my-envs\lib\site-packages\rasa\core\channels\console.py", line 101, in send_message_receive_stream async for line in resp.content: File "c:\app\miniconda2\envs \my-envs\lib\site-packages\aiohttp\streams.py", line 39, in __anext__ rv = await self.read_func() File "c:\app\miniconda2\envs \my-envs\lib\site-packages\aiohttp\streams.py", line 328, in readline await self._wait('readline') File "c:\app\miniconda2\envs \my-envs\lib\site-packages\aiohttp\streams.py", line 296, in _wait await waiter File "c:\app\miniconda2\envs \my-envs\lib\site-packages\aiohttp\helpers.py", line 596, in __exit__ raise asyncio.TimeoutError from None concurrent.futures._base.TimeoutError Transport closed @ ('127.0.0.1', 64497) and exception experienced during error handling 2019-12-02 02:32:56 ERROR asyncio - Task exception was never retrieved future: <Task finished coro=<RestInput.on_message_wrapper() done, defined at c:\app\miniconda2\envs \my-envs\lib\site-packages\rasa\core\channels\channel.py:392> exception=AttributeError("'dict' object has no attribute 'split'") created at c:\app\miniconda2\envs \my-envs\lib\site-packages\rasa\core\channels\channel.py:432> source_traceback: Object created at (most recent call last): File "c:\app\miniconda2\envs \my-envs\lib\runpy.py", line 193, in _run_module_as_main "__main__", mod_spec) File "c:\app\miniconda2\envs \my-envs\lib\runpy.py", line 85, in _run_code exec(code, run_globals) File "C:\App\Miniconda2\envs \my-envs\Scripts\rasa.exe\__main__.py", line 7, in <module> sys.exit(main()) File "c:\app\miniconda2\envs \my-envs\lib\site-packages\rasa\__main__.py", line 76, in main cmdline_arguments.func(cmdline_arguments) File "c:\app\miniconda2\envs \my-envs\lib\site-packages\rasa\cli\shell.py", line 101, in shell rasa.cli.run.run(args) File "c:\app\miniconda2\envs \my-envs\lib\site-packages\rasa\cli\run.py", line 114, in run rasa.run(**vars(args)) File "c:\app\miniconda2\envs \my-envs\lib\site-packages\rasa\run.py", line 56, in run **kwargs, File "c:\app\miniconda2\envs \my-envs\lib\site-packages\rasa\core\run.py", line 206, in serve_application endpoints.lock_store if endpoints else None File "c:\app\miniconda2\envs \my-envs\lib\site-packages\sanic\app.py", line 1133, in run serve(**server_settings) File "c:\app\miniconda2\envs \my-envs\lib\site-packages\sanic\server.py", line 885, in serve loop.run_forever() File "c:\app\miniconda2\envs \my-envs\lib\asyncio\base_events.py", line 534, in run_forever self._run_once() File "c:\app\miniconda2\envs \my-envs\lib\asyncio\base_events.py", line 1763, in _run_once handle._run() File "c:\app\miniconda2\envs \my-envs\lib\asyncio\events.py", line 88, in _run self._context.run(self._callback, *self._args) File "c:\app\miniconda2\envs \my-envs\lib\site-packages\spf\framework.py", line 512, in _handle_request stream_callback) File "c:\app\miniconda2\envs \my-envs\lib\site-packages\sanic\app.py", line 1002, in handle_request await stream_callback(response) File "c:\app\miniconda2\envs \my-envs\lib\site-packages\sanic\server.py", line 498, in stream_response self.request.version, keep_alive, self.keep_alive_timeout File "c:\app\miniconda2\envs \my-envs\lib\site-packages\sanic\response.py", line 110, in stream await self.streaming_fn(self) File "c:\app\miniconda2\envs \my-envs\lib\site-packages\rasa\core\channels\channel.py", line 432, in stream on_new_message, text, q, sender_id, input_channel, metadata Traceback (most recent call last): File "c:\app\miniconda2\envs \my-envs\lib\site-packages\rasa\core\channels\channel.py", line 406, in on_message_wrapper await on_new_message(message) File "c:\app\miniconda2\envs \my-envs\lib\site-packages\rasa\core\channels\channel.py", line 82, in handler await app.agent.handle_message(*args, **kwargs) File "c:\app\miniconda2\envs \my-envs\lib\site-packages\rasa\core\agent.py", line 486, in handle_message return await processor.handle_message(message) File "c:\app\miniconda2\envs \my-envs\lib\site-packages\rasa\core\processor.py", line 96, in handle_message await self._predict_and_execute_next_action(message, tracker) File "c:\app\miniconda2\envs \my-envs\lib\site-packages\rasa\core\processor.py", line 413, in _predict_and_execute_next_action action, tracker, message.output_channel, self.nlg, policy, confidence File "c:\app\miniconda2\envs \my-envs\lib\site-packages\rasa\core\processor.py", line 523, in _run_action await self._send_bot_messages(events, tracker, output_channel) File "c:\app\miniconda2\envs \my-envs\lib\site-packages\rasa\core\processor.py", line 445, in _send_bot_messages await output_channel.send_response(tracker.sender_id, e.message()) File "c:\app\miniconda2\envs \my-envs\lib\site-packages\rasa\core\channels\channel.py", line 185, in send_response await self.send_text_message(recipient_id, message.pop("text"), **message) File "c:\app\miniconda2\envs \my-envs\lib\site-packages\rasa\core\channels\channel.py", line 326, in send_text_message for message_part in text.split("\n\n"): AttributeError: 'dict' object has no attribute 'split' 替换为,或类似的内容:

>>

这是一个非常糟糕的风格:

for (int a = 0;a < nameRow;a++)
{
    cin >> candName[a], nameCol;  // << -- here
    cin >> votes[a], voteCol;     // << -- and here
}

请添加这样的大括号:

for (int c = 0; c < voteRow;c++)
    for (int d = 0; d < voteCol;d++)
        votes[c][d] = 0;

答案 2 :(得分:-2)

在标准输入流中,您只能采用一个由空格分隔的输入。 因此,不像二维数组的cin >> candName[a], nameCol;那样支持从标准输入流中进行for循环读取。 可能您想做这样的事情。

cout << "Enter a candidate's name : ";
for (int a = 0; a < nameRow; a++) {
    for (int b = 0; b < nameCol;b++) {
        cin >> candName[a][b];
    }    
}