我的std :: string是utf-8编码所以很明显,str.length()返回错误的结果.
我发现了这些信息,但我不确定如何使用它来执行此操作:
以下字节序列用于表示字符.要使用的序列取决于字符的UCS代码编号:
Run Code Online (Sandbox Code Playgroud)0x00000000 - 0x0000007F: 0xxxxxxx 0x00000080 - 0x000007FF: 110xxxxx 10xxxxxx 0x00000800 - 0x0000FFFF: 1110xxxx 10xxxxxx 10xxxxxx 0x00010000 - 0x001FFFFF: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
如何找到UTF-8编码的std :: string的实际长度?谢谢
我正在寻找如何在C++中打印,以便表格列宽度是固定的.目前我一直在使用的空间,做|和-,但只要数去两位数所有的走线变坏.
|---------|------------|-----------|
| NODE | ORDER | PARENT |
|---------|------------|-----------|
| 0 | 0 | |
|---------|------------|-----------|
| 1 | 7 | 7 |
|---------|------------|-----------|
| 2 | 1 | 0 |
|---------|------------|-----------|
| 3 | 5 | 5 |
|---------|------------|-----------|
| 4 | 3 | 6 |
|---------|------------|-----------|
| 5 | 4 | 4 |
|---------|------------|-----------|
| 6 | 2 | 2 |
|---------|------------|-----------|
| 7 | 6 | 4 |
|---------|------------|-----------|
Run Code Online (Sandbox Code Playgroud) 我有以下代码要打印:
cout<<current->bookId<<"\t\t"<<current->bookName<<"\t\t"<<current->year<<"\t\t";
cout<<"Checked out by student "<<current->storedBy<<endl;
Run Code Online (Sandbox Code Playgroud)
看起来像这样
BookId BookName Year Status
1000 Machine Learning 1997 Checked out by student 21000000
1200 Data Mining 1991 Checked out by student 21000020
1400 C++ How to Program 2005 Checked out by student 21000020
1500 Pattern Recognition 2000 Checked out by student 21000000
Run Code Online (Sandbox Code Playgroud)
我该怎么做才能做到这一点:
BookId BookName Year Status
1000 Machine Learning 1997 Checked out by student 21000000
1200 Data Mining 1991 Checked out by student 21000020
1400 C++ How to Program 2005 Checked …Run Code Online (Sandbox Code Playgroud) 我在做图表时遇到问题。我希望在同一行中输出图表,而不更改代码,也不使其水平。我希望使用 for 循环来解决这个问题,因为我可以迭代所有内容,因为我有相同的元素。
代码显示如下:
# include <iostream>
using namespace std;
class InterestCalculator
{
protected:
float principal_amount = 320.8;
float interest_rate = 60.7;
float interest = interest_rate/100 * principal_amount;
public:
void printInterest()
{
cout<<"Principal Amount: RM "<<principal_amount<<endl;
cout<<"Interest Rate(%): "<<interest_rate<<endl;
cout<<"Interest: RM"<<interest<<endl;
}
};
class LoanCalculator : public InterestCalculator
{
private:
int loan_term;
int month;
float month_payment;
public:
void displayVariable()
{
cout<<"Enter loan amount (RM): ";
cin>>principal_amount;
cout<<"\n\nEnter annual interest rate(%): ";
cin>>interest_rate;
interest_rate = interest_rate / 100;
cout<<"\n\nEnter …Run Code Online (Sandbox Code Playgroud)