如何逐字符扫描字符串并在单独的行中打印每个字符,我正在考虑将字符串存储在数组中,并使用for循环进行打印,但是我不知道如何...。 !!!
这是我的代码:
#include "stdafx.h"
#include<iostream>
#include<string>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
  string str;
  char option;
  cout << "Do you want to enter a string? \n";
  cout << " Enter 'y' to enter string or 'n' to exit \n\n";
  cin >> option ;
  while ( option != 'n' & option != 'y')
  {
    cout << "Invalid option chosen, please enter a valid y or n \n";
    cin >> option;
  }
  if (option == 'n')
    return 1;
  else if (option == 'y')
  {
    cout << "Enter a string \n";
    cin >> str;
    cout << "The string you entered is :" << str << endl;
  }
  system("pause");
  return 0;
} 
for (int i=0; i<str.length(); i++)
    cout << str[i] << endl;
而已 :)