不打印所有字母只是一个字母,但它需要在输入的字母后打印出每个字母

时间:2017-12-11 14:07:05

标签: c++

到目前为止它只是打印出z后a但是在a之后是b所以我想要它打印b c d e f g .... z

foreach ($facebookEvents as $facebookEvent) {
    if (!empty($facebookEvent['event_times'][0]['start_time'])) {
        foreach ($facebookEvent['event_times'] as $recurrence) {
            $eventsArray[] = [
                'type' => 'Facebook Event',
                'startdate' => date('Y-m-d', strtotime($recurrence['start_time'])),
                'endate' => date('Y-m-d', strtotime($recurrence['end_time'])),
                'startime' => date('H:i:s', strtotime($facebookEvent['start_time'])),
                'endtime' => date('H:i:s', strtotime($facebookEvent['end_time'])),
                'title' => $facebookEvent['name'],
                'description' => $facebookEvent['description'],
                'entity_id' => $event,
            ];
            $addressArray[] = [
                'town' => $facebookEvent['place']['location']['city'],
                'address' => $facebookEvent['place']['location']['street'],
                'postcode' => $facebookEvent['place']['location']['zip'],
                            // also event id from each $eventsarray
            ];
            $geolocArray[] = [
                'lat' => $facebookEvent['place']['location']['latitude'],
                'lng' => $facebookEvent['place']['location']['longitude'],
                            // also event id from each $eventsarray saved
            ];
        }
    } 
}
} catch (Exception $e) {
    $error = $e->getMessage();
    $env = config('app.name');
    $command = 'Facebook Recalculate';
    Notification::route('slack', 'https://hooks.slack.com/services/T30BGA1EW/B7A9TEC3F/N0FqRyzdsdsdsDN5SVxiN')
    ->notify(new JobErrorNotification($error, $env, $command));
}
}
$event = Event::insert($eventsArray);
    //save address array and add $event->id for each one
    // same for geoloc
$algolia = Event::all()->searchable();
}

我只是在寻找一些如何做到这一点的帮助然后我需要输入2个字母并用2个字母做,但这只是为了我,我知道这不是代码编写服务只是寻求一些帮助怎么做。谢谢任何帮助都很好

3 个答案:

答案 0 :(得分:3)

在循环中,您需要在括号中包含多个语句:

int main() 
{
    char a = 'a';
    while (a < 'z'){
        a++; 
        cout << a; 
    }
    cout << '\n'; // let's have a line break at the end
}

否则cout语句仅在循环结束后运行。

遗憾的是,这段代码不可移植,因为C ++标准要求对字母字符编码的方式提出几点要求。并且它们是连续的并且连续不是必需的。便携式解决方案基于显而易见的表面上的幼稚

int main()
{
    std::cout << "abcdefghijklmnopqrstuvwxyz\n";
}

如果你想从打印所有字母某个值,那么就使用

行中的内容
int main() {
    const char* s = "abcdefghijklmnopqrstuvwxyz";   
    char a = 'k'; // print from k onwards, for example
    for ( ; *s /*to prevent overrun*/ && *s != a; ++s);     
    std::cout << s; 
}

答案 1 :(得分:2)

需要将cout放在循环中:

#include <iostream>

int main() 
{
   char a = 'a';
   while (a < 'z')
   {
      a++; 
      std::cout << a << " "; 
   }
}

还添加了一个空格来区分不同的字母。并删除using namespace std;,因为不推荐。

答案 2 :(得分:1)

只有在while中执行的是++;因为没有括号围绕属于while的语句。用括号括起来做多个语句。或者就像在这种情况下,可以将它们组合成一个陈述。

#include <iostream>

int main() 
{
    char a = 'a';
    while (a < 'z')
        std::cout << ++a;
}