我该如何纠正这个程序? [英] how can i correct this program?

查看:63
本文介绍了我该如何纠正这个程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include "stdafx.h"
#include <iostream>
#include <string>

using namespace std;
int main () 
{
  string myString = ""; 
	cout<<"enter the sentence"<<endl;
	getline(cin,myString);


myString.insert(10, 1, ''\n''); 
myString.insert(20, 1, ''\n'');
myString.insert(30, 1, ''\n'');
myString.insert(40, 1, ''\n'');
myString.insert(50, 1, ''\n'');
myString.insert(60, 1, ''\n'');
cout << myString << endl;


    return 0;
}</string></iostream>







or

using namespace std;
int main () 
{
  string myString = ""; 
	cout<<"enter the sentence"<<endl;

	getline(cin,myString);
	 
    	cout.width(10);
        cout <<myString << "\n";



它没有任何错误,但不起作用



it does not have any error but it does not work

推荐答案

使用cin可能不是最佳选择,因为它会破坏空格本文(告诉您cin的问题,并向您展示如何使用getline):
http://www.cplusplus.com/forum/articles/6046/ [
Using cin is probably not your best option for this, since it breaks on a space character, see this article (tells you problems with cin and shows you how to use getline instead):
http://www.cplusplus.com/forum/articles/6046/[^]


任何人最大的问题develeoper(这不取决于您使用的语言)是为了阐明程序应该执行的操作.如果可以的话,程序就已经准备好了.您是否需要帮助-请告诉别人您愿意做什么.
问候.
The biggest problem for any develeoper (this don''t depend on the language you use) is to articulate what the program should do. If you can do that the program is as good as ready. Do you want help - please tell somebody what you''re willing to do.
Regards.


这篇关于我该如何纠正这个程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆